Suppose that we have 1000 documents that are shared by 1 million active clients. And suppose we do an update on all of those documents (or a large portion of them). How does sync gateway prevent that those clients will request those updates all at the same time? How does it prevent an overload on itself or on the database?
How does sync gateway prevent an overload when documents are updated that are shared by many clients
Yes, the “thundering herd problem.” We don’t have anything set up to prevent it (by delaying change notifications), since the general goal is to reduce latency. It’s possible some kind of heuristics could be used in the future to control this, but that hasn’t been researched yet.
What does happen is that an overload at the database level is caught by Sync Gateway and causes a 5xx status to be returned to the client. The client interprets this as a transient error and will pause and retry the request, with an exponentially increasing backoff. In lab tests we’ve found this works pretty well to control the load.