R
Railway14mo ago
quan

access to resource inside replica

hi, when we setup an instance to have 2 replicas, how do we get the resource related to 1 of the rep, hm I can't find the info from the docs though for a simple scenario, we have a /get-users to returns a list of in-memory users array in one instance, and /add-user to add an entry to the array so hitting the add endpoint one time, and get just returns the values of one random replica, either an empty array, or array of 1 val added previously
19 Replies
Percy
Percy14mo ago
Project ID: N/A
luna
luna14mo ago
You’ll want to use a database if you’re running multiple replicas of a service.
Brody
Brody14mo ago
that's 2 for 2 on the use a database solution
luna
luna14mo ago
If you’re expecting to be able to hit a certain replica you’re misunderstanding what replicas are.
quan
quan14mo ago
ok, yea we are using sse, we store the response obj from client for sending the event-stream over I can't find the info yet but I think we can't save that into a db... but thanks for the info though
luna
luna14mo ago
Why not? 🤔 Sounds like a good use case for redis.
Brody
Brody14mo ago
I also think it's worth asking, are you sure you need any replicas?
luna
luna14mo ago
Redis pubsub with channels based on the users connection ID would likely be fine for this.
quan
quan14mo ago
yea, i can't run any benchmark right now, but I just need to have a rep ready for there are many connections, we used short polling previously and on peak we had 5-6k ppl concurrently
Brody
Brody14mo ago
are you a part of a railway team?
luna
luna14mo ago
Even with that amount why do you think you need a replica? I’ve had multiple projects with 50k clients on a single instance. Replicas are for scaling load. If your single service can keep up with the load a replica isn’t gonna really do much but add complexity.
quan
quan14mo ago
oh, is it on a normal 8gb ram instance for 50k clients, I can hop to a team but was just using the hobby plan initially i meant i can turn to the team eventually
luna
luna14mo ago
Depends on the load. In the case of the 50k clients we were using a 1GB digital ocean box. People way too often see a big number and instantly think they need to scale without actually seeing if they’re hitting any kind of limit. If you’re doing this all in memory and move to using a database you may find you don’t need the replica after all since the memory footprint could very likely drop down to almost nothing.
quan
quan14mo ago
i see, thanks for info. let me try the benchmark for now ah i think the res we store in memory is a stream object, i remember we were having issue serialize the object on db query, to use that obj to stream the info back from nodejs => client for server sent event really appreciate
luna
luna14mo ago
What’re you sending to the client that’s a stream? If it’s a file then that’s not memory intensive. If it’s something from another client then look at pub/sub.
quan
quan14mo ago
ah ok
luna
luna14mo ago
just having a client connected uses very few resources, copying a stream to a connection is also really cheap in terms of resources so unless you're doing a bunch of computational work you'll likely see a big decrease in memory usage once this is all moved to a db.
quan
quan14mo ago
ok yea its not having any big computation, we have other servers already doing the math, we just have this server alone to send / notify data back to client when data is published from a redis when a channel / topic matches
luna
luna14mo ago
yeah in that case you shouldnt be needing more than a gig or so of memory if it's all done correctly.
Want results from more Discord servers?
Add your server