PSA for anyone implementing distributed rate limiting with Redis: INCR + EXPIRE has a race condition. If your process crashes between the INCR and the EXPIRE, that key lives forever and your counter never resets.
Use a Lua script or MULTI/EXEC pipeline to make the increment-and-expire atomic. Or use sorted sets with sliding window logs where each entry self-expires. Either way, test by killing processes mid-request.
#SRE #RateLimiting #Redis #ProductionEngineering #Programming #DevOps #Tech
