I have two separate servers, A and B, each with its own database and private cache systems like Redis or Memcached. There's no shared database or cache between them, and I'm dealing with a POST request for domain registration involving an account ID and a domain name. I want to make this operation idempotent so that retries or clicking multiple times don't create duplicates. If a request hits Server A but a retry hits Server B, neither server has access to the other's idempotency key or cached results. How should I approach idempotency in this situation? Is a shared store absolutely necessary or are there other strategies to manage this?
1 Answer
If you’re using a load balancer, you could set up a session affinity policy so that the same server handles all requests from a given session. This might decrease the chances of duplicate processing. Just keep in mind, though, that session affinity won’t fully guarantee correctness. If something happens to the server, like a crash or scaling, the retries could still hit a different server that doesn’t have the previous request data, leading to potential duplicates.

You raise a good point. Session affinity helps, but it’s not a complete solution for idempotency. If a server fails or is taken offline, the requests can still end up misrouted and cause issues.