Race Condition
For example, 2 concurrent requests may concurrently read and write to the rate limiting counter, resulting in lower than expected counter value.
In Alex Xu's system design book (volume 1), it is stated that the race condition can be fixed by 2 approaches: Lua script and Redis's sorted sets. Should we just tell the interviewers details of these approaches? Is there a more generic way to answer this type of race condition question?
Data Synchronization
In the book, it is also stated that we can synchronize data with an eventual consistency model to optimize performance. There is no more discussion on how this can be achieved.
Isn't eventual consistency may result in incoherent data (i.e., different counters) between Redis distributed cache replicas? Or is this still fine as we are writing and reading using primary replica, and only switch to secondary replica if the distributed cache is down, so some incoherent data is fine as this only allows slightly more than expected requests?