database - Can redis do hundreds of transactions per second on single key-value pair -
i have application, works on api calls. on every api call perform task , charge it(which can sending mail or sms or such thing).
currently keep users balance/credit data in mysql table in following form :
|user|balance| |a |1200 | |b |1200 | |c |1300 | |d |1400 | |e |1212 | |f |9000 | |g |8000 | |h |7000 |
but creating problem when single users hits thousands of apis per minute.and on every api update users balance , if there not sufficient balance, return error.
when no of api hits small , there no issue when large, updating balance creates lock on row , other apis have wait process.
i thinking of moving table cache or in-memory database, can fast process.
earlier had memcache in mind volatile , on searching read redis.
but confused, problem solved or not? different keys, fetching data redis may fast,as kept in memory/ram only, how work if there thousands of update , search queries same/single key.
please share if have knowledge or experience regarding or if has better solution problem redis, please help.
in short, yes, redis accomplish you're looking do. can handle high throughput, can configured persistent, , can set in ha manner sentinel. having handle level of thousands of api calls minute should no problem @ all.
that said, it's not necessary. if you're ok having few second lag in declaring users when they're out of credits, i'd recommend caching number of api calls per box , flushing db (either redis or mysql) every few seconds total amount of credits used/added per box during time. adding/subtracting numbers should idempotent, , flushing every few seconds should resolve main issue of not being able handle unexpectedly large amounts of mysql hits @ random times.
so, you've got few options here. pick whichever makes sense use case.
Comments
Post a Comment