r/Backend • u/RAJATSDE • 7d ago
Auto scaling made our Node.js API worse until we fixed the Redis layer. How do you handle this?
[removed]
0
Upvotes
r/Backend • u/RAJATSDE • 7d ago
[removed]
2
u/sereikis 7d ago
replicas aren't pointless here: Sentinel or a managed failover service addresses availability without sharding; Redis Cluster is for partitioning the workload across primaries. since Redis now holds sessions and rate limits, test a primary failure during scale-out and decide explicitly how requests behave while Redis is unavailable; asynchronous replication can also lose acknowledged writes during failover.
1
u/abcd98712345 7d ago
don’t use replicas w redis you are paying for HA when redis shouldn’t be used with that in mind. use either cluster or hand roll by just connecting to multiple instances w a ring hash or other type of shading approach. also if you actually need scale ditch JS for an actual real backend appropriate server language like go rust zig or (vomit) java/kotlin.
if you are slamming mongo on scale out then you are designing things wrong. have a simple leader election mechanism to periodically load your mongo crap into redis and then when apps start up they can pull from redis. if it’s a crap ton you are caching in memory you could alternatively store that in s3/gcs kind of thing to avoid causing redis itself to get too overloaded.
mongo itself / docdbs aren’t great at high volumes so if you did actually need to scale to something super high i would think how you could minimize read load on mongo as much as possible if it’s truly essential to be your SOTs for writes and basically try to have writes go to mongo but anything high traffic read wise not hit mongo.
1
u/opportify 7d ago
For the load test question, the thing that usually makes it unrealistic is a closed model, where each virtual user waits for a response before sending the next request. When the API slows down, load drops with it, so you never see the pile-up. k6's ramping-arrival-rate executor keeps requests arriving at the rate you set no matter how slow responses get, which is closer to what a real burst looks like.
Make the ramp steeper than your scale-out time (instance boot plus health check), so the test actually covers the gap before new capacity is ready. And terminate a couple of instances mid-run to exercise the SIGTERM drain too.
1
u/Discordbothost 6d ago
Run the same traffic spike twice in staging, once pre-scaled and once from the normal minimum. Plot when new targets first take traffic against Mongo pool wait time. That shows whether the extra capacity helps once it's serving.