Durable object - max websocket connections

Hi

What is the maximum numbers of websockets a durable object can support?

Once GA hits, probably unlimited, other than the limit placed on a per-zone (and “how much load is this Datacenter under”) level as described here:

Although, with enough connections, you’re bound to hit internal throughput bottlenecks. If you do, you can create a thread here when it happens and/or contact support with the issue.

So making connections to the same durable object (ie the same id) will mean it scales automatically in the background for me? Does this mean there is another identity underneath?

It doesn’t sound like that from the docs, but I can’t say for certain. Maybe someone else here that has experimented with Durable Objects+Websockets at scale can weight in, or @KentonVarda :wink:

There’s no explicit maximum number of connections to a single object. However, a single object runs on a single thread, and therefore is inherently limited to what it can process in that thread. If an object can’t keep up with the load, then some requests to it will start failing.

So if new WebSockets are added gradually, and each one is mostly quiet, then you’ll be able to establish more connections compared to if they all connect at once or send lots of messages. It all depends on what your app is doing.

With all that said, if you are connecting a large number of WebSockets to the same object, I would recommend thinking about replication and sharding schemes to allow load to be distributed over more objects. For example, you might have a two-layer system, where you have one class defining “root” objects, and another class defining “replicas” that sit in front of them. You could have, for example, 10 replicas per root object. WebSockets would connect to the replicas, and then each replica would synchronize state with the root and/or with other replicas. This approach might allow you to handle 10x the connections. Of course, the number 10 is chosen arbitrarily, it could be 50 or 100 or whatever. (But at some point you might need three layers, etc.)

How best to design this really depends on the details of your application. Durable Objects are a tool that can be used to build distributed systems, but you may still need to design a replication strategy on top of them.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.