0

I am using an Nginx proxy as a front-end to a web application that tends to get identical duplicate requests milliseconds apart, causing duplicate items in my database.

I thought I might be able to fix this by letting Nginx cache content for 1s, so that duplicate requests would not hit my app at all

I configured it with

proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=prevent_duplicates:10m max_size=1g inactive=1s use_temp_path=off;

And then added proxy_cache prevent_duplicates; to my root location section, where I have proxy_pass

But my application gets hit on all requests anyway - is it a timing thing? Multiple threads all starting at once for each request all thinking they are first?

7
  • 1
    That sounds more like bad app/DB programming.
    – tater
    Sep 1, 2020 at 14:02
  • Unfortunately I have no control over the client in this case - the client will always make 2 calls to the application in a row. I can fix it app-side but I thought this would be a cleaner solution Sep 1, 2020 at 14:09
  • Eh? Fixing the app is the clean solution. This is just a workaround. Sep 1, 2020 at 18:57
  • 1
    Microsoft is very much not going to modify Explorer's webdav redirector on my account. I frankly don't really care if you think it's the clean solution or not, I would appreciate it if you would just answer my question instead of commenting on the architecture of my solution Sep 2, 2020 at 11:07
  • 1
    And even if I miraculously got this problem solved client side, it would be exactly 0 help to me since I absolutely cannot depend on every client computer installing patches because of the nature of this application. Nginx proxy is part of my Docker compose stack which is part of my application. So unless y'all have another way of preventing Explorer from retrying a webdav connection that has failed ( which I have intended it to do!) I would appreciate it if you would stop assuming things about my application architecture and actually answer my question Sep 2, 2020 at 11:16

1 Answer 1

1

Maybe rate limiting can be the solution?

limit_req_zone $binary_remote_addr zone=mylimit:10m rate=1r/s;
 
server {
    location /login/ {
        limit_req zone=mylimit;
        
        proxy_pass http://my_upstream;
    }
}

Source: https://www.nginx.com/blog/rate-limiting-nginx/

The rate=1r/s can be tweaked, if you put 2r/s NGINX will allow 1 request every 500 milliseconds...

2
  • I ended up adding a local cache to filter duplicates - it cannot scale since instances do not share a cache but it works for now Sep 23, 2020 at 13:33
  • Great, happy that you found a solution. This will probably be the last thing I ever write on Stack Exchange Sites as the communities around here are very prickish and trollish. Wish you all the best. Sep 24, 2020 at 14:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .