#access to resource inside replica

25 messages · Page 1 of 1 (latest)

neat spade
#

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

mild sigilBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

prime oceanBOT
#

Project ID: N/A

rustic heart
#

You’ll want to use a database if you’re running multiple replicas of a service.

odd beacon
#

that's 2 for 2 on the use a database solution

rustic heart
#

If you’re expecting to be able to hit a certain replica you’re misunderstanding what replicas are.

neat spade
#

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

rustic heart
#

Why not? 🤔

#

Sounds like a good use case for redis.

odd beacon
#

I also think it's worth asking, are you sure you need any replicas?

rustic heart
neat spade
#

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

odd beacon
#

are you a part of a railway team?

rustic heart
#

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.

neat spade
#

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

rustic heart
#

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.

neat spade
#

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

rustic heart
#

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.

neat spade
#

ah ok

rustic heart
#

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.

neat spade
#

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