I need an implementation of an Atomic Counter on cloud to produce a serial integer from concurrent connections. The business behind is a tracking server.
CREATE SEQUENCE serial CACHE 100; SELECT nextval(sequence)
- 140$/m MultiAZ AWS RDS db.m3.medium not not as fast as redis but I think is < 7ms in average. the "cache" is a strong feature that should boost performance.redis has INCRBY, and postgres only has the "cache" feature of sequence which requires roundtrip to the DB.
Any input? regarding those two alternatives or others?
I think you are overestimating the risk of a redis failure that leaves it unable to flush to disk and underestimating the risk of any RDBMS doing the same. The risk can be mitigated in both by syncing writes to disk.
In redis this means switching to AOF (Append Only File) mode, as described in the persistence link you already link to.
There is no need to do any expiring key trickery. The atomic behavior of incr
and incrby
are more than sufficient to ensure uniqueness and durability, especially when combined with AOF persistence.
Redis is just about perfect for this use case. It is fast enough and scaleable. Redis has been around a while now. There are no legitimate durability concerns that wouldn't also be concerns for PostgreSQL or MySQL.
As noted by @Solarflare having applications grab blocks of IDs at a time is even more cost effective and scaleable. This can be accomplished in redis using incrby
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With