Synapse sync load balancing across workers

Routing Synapse sync, login and event sending to the right generic workers needs a reverse proxy with correct sticky rules. This page explains the routing decisions, setup sequence, checks and limits to confirm.

On this page

Why Synapse sync load balancing becomes a planning task

When the main process of a Synapse homeserver is saturated by client sync and login requests, the fix is no longer a bigger machine alone. You need to split that traffic across worker processes, and the reverse proxy in front of Synapse must send each request type to the process that is allowed to handle it. The Synapse workers documentation describes the generic worker as handling client, federation and event traffic, so the routing layer decides which requests reach which process. Getting that layer wrong can leave a worker serving requests it was never configured for, or leave the main process doing work you meant to offload.

Teams usually reach this point when sync latency climbs under concurrent clients, when login spikes stall other users, or when the main process shows sustained high CPU in its own metrics. No published threshold is supplied for this decision, so confirm the trigger with the Synapse workers documentation and with your own measurements over a representative period. Record sync and login response times, process CPU and database load before you change anything, so you can tell later whether the split helped. Also confirm which Synapse version you run, because worker options and routing rules change between releases and the upgrade notes should be read for each one.

This page covers the routing layer: how requests are matched, which paths and methods go to which worker, and how sticky routing keeps a client's traffic on one process. It does not explain the worker types themselves, the Redis replication setup or the decision to shard event persisters, which are covered by the sibling sections and topics. Plan the routing rules as a reviewed configuration artifact with an owner, because a mistake there appears as intermittent client errors rather than a clear failure. Ask your team to test the rules against a staging homeserver with real client behavior before any production change.

How client requests reach the main process and generic workers

Traffic starts at clients and federated servers, which both reach the reverse proxy on its public listeners. The proxy sends requests for /sync, login and event sending to generic workers and everything else to the main process, so each worker must receive the same user's requests consistently. The main process and every worker also connect to Redis, which relays replication between them on a private network. Check that the replication listener is not reachable through the proxy, and that the routing rules match the Synapse worker documentation for your version.

Client and federation traffic routed by the proxy, with replication kept on a private Redis path.

How the generic worker handles sync and client traffic

The generic worker is the Synapse worker process that takes over most of the traffic a client or another server sends to the homeserver. According to the Synapse workers documentation, it serves client, federation and event traffic, while the main process and every other worker connect to Redis, which relays replication between them. Before you place a load balancer in front of several generic workers, copy the endpoint list from the current workers page of the Synapse documentation and check it against the exact release you run. The list changes between releases, and a route you route to the wrong process type can fail silently. Confirm each route group in your own configuration file rather than relying on a list from memory.

Sync is the hard part of this routing. A /sync request depends on a stream position that a process tracks for a specific user and device, and that state lives in the memory of the worker handling the stream. If the next sync request reaches a different generic worker, that worker may not hold the same position, so the response can be stale, incomplete or rejected. The same risk applies to the initial sync and to login flows that create session state. For this reason, the proxy must send all requests from one client session to the same worker, using a stable key such as the access token or the user and device identity, and the mapping must survive normal client retries. Plan the routing key before you write any location blocks, because changing it later means reviewing every route.

A request that lands on the wrong process does not always produce a clear error. The client may receive an old view of a room, miss events that arrived on another worker, or repeat a send that already succeeded. Test sticky routing with a single account that logs in, syncs, sends a message and reconnects through the proxy, then compare the results with a direct connection to the main process. Also confirm how your proxy behaves when a worker restarts, because existing sessions will move to a new process. Ask your team to define what they will observe during a failover test, and record the expected behavior before the cutover.

Routing options for nginx and HAProxy

This table compares the practical ways to route Synapse sync, login, event sending and replication traffic to workers with nginx or HAProxy. Read each row as a decision point, then confirm the route list and listener details in the Synapse workers documentation before you commit to a layout.

DecisionOptionMain trade-offConfirm before choosing
Routing syntaxnginx map or location blocksCompact for a fixed route list, but route changes need careful reload testing and map logic gets hard to read as routes growThe current list of endpoints the workers docs assign to generic workers and which must stay on the main process
Routing syntaxHAProxy ACLs with separate backendsClear backend per worker group and visible health checks, but more config files and backend definitions to keep aligned with SynapseWhich request paths require a single writer and which can be spread across several instances
Worker countOne generic worker for all client trafficSimplest to operate and debug, but one process limits sync throughput and gives no spread across instancesWhether your sync and login volume fits one process, based on your own monitoring of the existing server
Worker countSeveral generic workers with hashed sticky keysSpreads load, but requests must hash consistently by user or room, and worker set changes need a planned restartThe sticky key the docs specify for each route, and whether the hash key is taken from the client IP, token or path
Replication listenerReplication on a private network address behind the same hostWorkers reach the main process directly, and the listener is not exposed to clients, but the proxy must never forward itThe replication listener settings and the required Redis configuration in the workers docs
Federation listenerDedicated federation worker on its own listenerLets you firewall federation traffic separately, but adds a second public-facing route to secure and monitorThe federation listener port and whether your delegation points federation traffic at the proxy or directly at the worker
Failover behaviorProxy health checks that remove a failed workerRequests can reach another worker, but sticky routes may move users and in-flight sync requests can failHow the docs describe failure handling for each route and whether a failed worker can be replaced without a full restart
Operator familiarityTeam already runs nginx for other servicesLower learning cost for routine changes, but the team must know which Synapse routes are exposed and whyWhether your platform team already has validated nginx or HAProxy configuration patterns for Synapse

Setting up the routing layer in sequence

This sequence moves sync, login and event-sending traffic from the main Synapse process onto generic workers behind a reverse proxy, in an order that keeps the replication listener private and lets each route be checked before the next one changes.

  1. Confirm the worker layout and Redis

    The platform engineer confirms that the main process and every planned worker can reach a running Redis instance, and that Redis is reachable only on a private network with authentication configured as the reader's chosen option requires. Check Synapse's logs for each worker reporting a successful connection to Redis and to the main process before touching the proxy. Done means every process starts cleanly and no client traffic has been changed yet.

  2. Define worker names and listeners

    Using the workers documentation for your exact Synapse release, the engineer declares each generic worker in its own worker config file, giving each a unique instance name and a listener bound to a private address. Confirm the names and listener types against the documentation, since the config keys and file names change between releases. Check that each worker starts and registers with the main process, and that the main process logs show the new instances connected.

  3. Write the proxy routing rules

    The engineer translates the route list from the workers documentation into nginx or HAProxy rules, sending sync, initial sync, login and event-sending paths to the generic workers while all other paths stay on the main process. Where the documentation calls for sticky routing, the rules key requests consistently by user or access token, so a client's session always reaches the same worker. Review the file with a second engineer; done means the configuration passes the proxy's syntax test.

  4. Keep the replication listener off the proxy

    The engineer confirms that the replication port is not published through the public reverse proxy, and that firewall rules permit it only between Synapse processes on the private network. From an external host, a connection attempt to the replication port should fail. This check matters because the replication listener is not meant for client traffic, and exposing it would let outside callers reach internal endpoints.

  5. Reload and test one route at a time

    After reloading the proxy, the engineer sends a test sync request using a non-production account and reads the access log or the worker's log to confirm the request was served by the expected worker. The same test is repeated for login and for sending an event. Done means each route lands on its intended worker and the requests succeed from a real client.

  6. Confirm the main process no longer serves the moved paths

    The engineer repeats the test requests for each moved path and checks that the main process logs no longer record them, while requests to paths kept on the main process still succeed. Any path still served by the main process after the change is a missed route in the proxy rules and should be added to the workers documentation list. Done means the routing map matches the documented design and the main process handles only the traffic it was assigned.

  7. Record the routing map and rollback steps

    The engineer saves the final proxy configuration, the worker names and the test results in the change record, along with the previous proxy configuration so the routing can be reverted. Ask the Synapse release notes for any rollback limits before the change goes live, because schema changes between releases can make some rollbacks difficult. Done means a second engineer can reproduce the routing layer from the record alone.

Sticky routing rules for nginx and HAProxy

In nginx, the routing intent is expressed with location blocks that match client paths, upstream blocks that group workers, and map or hash directives that choose a worker for each request. The configuration below is illustrative and shows the shape of the rules, not a file to copy. The path expressions change between Synapse releases, so take them from the workers documentation for your version.

  • Sync paths: a location block matching the client sync endpoints proxies to an upstream that lists only the workers allowed to serve /sync.
  • Login and registration paths: login routes go to a separate upstream, so authentication spikes do not compete with long-polling sync requests.
  • Sticky selection: a hash directive with the consistent parameter keys on a value that stays constant for one user or device, such as a header or a variable you set from the access token. nginx does not extract Matrix identifiers natively, so this usually requires a map or a scripting module.
  • Event sending: room send paths go to the event-capable workers, and the same stickiness key is applied so one client's sends are not split across processes.
  • Private listeners: the replication listener and any admin or metrics endpoints have no public location block at all.

Before relying on the hash key, confirm in a test environment that the same user or device consistently lands on the same worker across repeated requests.

Security risks in a split worker deployment

Splitting Synapse into workers adds listeners, a Redis bus, a routing layer and a set of per-worker settings, and each one is a place where traffic can reach a process it should never touch. The cards below cover the controls that most often go wrong, and each one names where the setting lives so your team can check it on the running system.

Replication listener exposed publicly

The replication listener lets workers talk to the main process and carries internal stream data. If it binds to a public interface or is reachable through the proxy, anyone who can connect can inject or read replication traffic. Check that the listeners blocks with type: http and resources: replication bind only to a private address, and that the reverse proxy never forwards /_synapse/replication paths. Confirm with a connection test from outside your private network.

Synapse workers docs

Redis reachable beyond workers

Redis relays replication between the main process and every worker, so anyone who reaches it can observe or disrupt the whole deployment. Keep Redis on the same private network as the workers, require authentication, and block it at the host and network firewall. Check the redis block in the homeserver configuration and the bind and password settings in the Redis server itself, since a default Redis install may listen on all interfaces.

Admin endpoints on general workers

Admin API routes change users, rooms and server state, and they should run only on the main process or a dedicated admin worker. If your routing map sends /_synapse/admin to a generic worker, any client who can reach that worker may call administrative functions. Review every location block in the proxy against the endpoint list in the worker documentation, and confirm that admin paths return an error from the public listener.

Forwarded headers from clients

Synapse uses X-Forwarded-For and X-Forwarded-Proto for client IP and scheme in logs, rate limiting and some checks. If the proxy passes these headers through unchanged, a client can set its own address and bypass per-IP limits. Configure the proxy to overwrite these headers with values it sets itself, and list only your proxy addresses under the trusted proxy settings of the listener. Test by sending a forged header and confirming the logged address does not change.

Hostname and TLS mismatch

When the proxy terminates TLS and talks to workers over plain HTTP or a different hostname, certificate checks, server_name expectations and Host header routing can disagree. Synapse may then build URLs or identify requests incorrectly, and internal hops may run unencrypted across shared networks. Decide whether internal traffic is encrypted, match the certificate names to the hostnames used in the routing file, and confirm the Host header that reaches each worker matches the value Synapse expects.

Logs that record tokens and IPs

Request logs from the proxy and from each worker can capture access tokens in query strings, client IP addresses and user identifiers. Once every worker writes its own log, the exposure multiplies and retention differs by host. Review the proxy log_format so it omits query strings on /sync and login paths, set a retention period for each log location, and restrict who can read them. Ask your security team to sample the logs after the first load test.

Routing file drifts from the worker set

The routing map and the list of worker processes are maintained in separate places, so adding, renaming or removing a worker can leave a route pointing at a process that no longer exists or sending traffic to a worker without the right type. Keep the proxy configuration and the worker configuration files in one version-controlled repository, and deploy them together. After each change, compare the set of worker names in the routing file with the running processes and confirm each route answers on its intended worker.

How to verify that routing works before users depend on it

Treat routing as unproven until each request type has been traced to the worker you intended. Before any user is moved onto the new layout, run a scripted set of client actions against the load balancer hostname: a login, a full initial sync from a fresh device, an incremental /sync with a since token, and sending a message to a test room. Use the same client each time so the traffic follows the same path. For every action, confirm in the logs of the generic worker named in your nginx or HAProxy map that the request arrived there, and that the main process did not handle it. A request that succeeds but lands on the wrong process still passes a simple smoke test, so the log check is the part that matters.

Next, confirm that the replication plumbing is healthy, because the routing rules depend on it. Each worker must connect to Redis, and the replication log on every process should show a successful connection rather than retries. Check that the replication secret matches across the main process and all workers, and that the replication listeners are reachable only on your private network. Then simulate a restart of one worker and watch its logs and the client test for errors such as stream position gaps, 404 responses on a route that worked a minute earlier, or sync requests that stall. Repeat the test after any change to the set of workers. Confirm with the Synapse workers documentation which changes require restarting the main process and the workers, since a change to the worker set can require a coordinated restart. Ask whether your deployment can tolerate that restart, and schedule the verification run before any user traffic is switched over.

Keep the test evidence with the configuration so that the next change can be checked the same way. Record the exact test script, the expected worker for each request type, and the log lines that prove it. Repeat the run after each Synapse upgrade, since upgrade notes can change worker configuration, and after any edit to the routing map. A short written pass or fail result for each request type gives operators a baseline to compare against when a user later reports a slow or failed sync.

Limits and facts to confirm in your environment

Synapse routing rules change with releases, and proxy features vary by version. The cards below list what to verify against your own release, proxy and traffic before you write the routing configuration. Each item affects whether the load balancer sends requests to the right worker.

Endpoint routing list for your release

The set of client and federation paths that may be sent to generic workers changes between Synapse releases. Take the list from the workers documentation for the exact version you run, not from an older guide or a blog post. Check every path your load balancer config routes against that list, and confirm which paths must stay on the main process. A path that is missing from the list falls through to the wrong process or returns an error.

Synapse workers docs

Proxy support for header and map features

The routing approach depends on map blocks, request header handling and, for HAProxy, the variables and ACL syntax available in your version. Confirm that the proxy version you run supports each directive in your configuration, including the features used to pass the requesting user or device to the correct worker. Test the configuration syntax on the exact proxy build before it reaches production.

Synapse, Python and PostgreSQL floors

Your release sets the minimum runtime you must run. Synapse 1.143.0 and later require PostgreSQL 14 or newer, and 1.142.0 and later require Python 3.10 or newer. Check these floors against your current database and host images before you change the routing layout, because a worker rollout that also requires a platform upgrade mixes two sources of failure.

Synapse upgrade notes

Load testing for your user count

Synapse does not publish a performance figure that transfers between deployments, so the right number of sync and send workers depends on your own traffic. Build a load profile from your real user count, device count and sync frequency, then test the routed configuration against it. Measure sync latency, event send latency and main process load before and after the change. Plan this test as part of the project so the results decide the worker count.

Client and federation paths the proxy misses

Clients and federated peers can call endpoints that your routing rules do not cover, especially newer client features, media paths and server-to-server requests. Capture real access logs for a representative period and compare every requested path with your routing rules. Paths that reach the main process without a rule show up as unexpected load there. Keep federation traffic on its own listener rules and confirm each path against the federation documentation.

Synapse federation docs

Questions buyers ask before hiring help with Synapse sync routing

What drives the cost and effort of a Synapse sync routing change?

The main drivers are how many worker types already exist, how much of the routing is hand-written in nginx or HAProxy, and how many client and federation paths reach the homeserver through the proxy. A deployment with one generic worker and a single proxy config is a smaller job than one with separate sync, login and event-sending pools, Redis replication and custom monitoring. Cost is mostly skilled engineering time for reading the current config, writing route maps, testing sticky sessions and checking traffic on each worker. One-time work covers the design and cutover. Recurring work covers keeping the routing aligned with each Synapse upgrade, because the set of endpoints that need routing can change between releases. When you ask for a quote, ask which routes are in scope, how many environments will be tested, and whether monitoring changes are included.

How long does a Synapse sync load balancing project take?

Duration depends on the environment and the scope, so no fixed figure applies here. A single-site homeserver with an existing worker layout and a staging copy usually moves faster than a multi-site deployment with custom load balancer rules, several worker pools and a change window agreed with other teams. Time is spent on inventory of current traffic, drafting the route map, testing each endpoint class in staging, observing behavior under realistic load and rolling out in stages. Ask any provider to break the timeline into discovery, build, test and cutover, and to state which dependencies, such as a Redis or PostgreSQL change, would extend it.

What must our team provide before a routing engagement starts?

Start with the current proxy configuration, the exact Synapse version in use, and the worker configuration files that define each process and its listeners. Add recent metrics for request rates, latency and error codes by endpoint, plus any logs that show sync or login failures. Provide a description of your clients and their expected sync behavior, and of any federation traffic that reaches the same proxy. Finally, supply a test plan or the criteria you will accept, including a staging environment that resembles production. Without these inputs, a provider can only propose a generic design, and the first weeks of work go to discovery rather than routing.

Can our in-house team handle Synapse sync routing without outside help?

Yes, if the team has working knowledge of Synapse worker types, the replication setup over Redis, and the reverse proxy in use. The skills needed include reading the Synapse workers documentation carefully, writing and testing nginx or HAProxy rules, understanding which endpoints require sticky routing, and interpreting metrics well enough to spot a regression. The harder part is maintaining that knowledge across Synapse upgrades, since routing rules and worker options can change. Teams without a second engineer familiar with the setup often find that a short external review of the design, the test plan and the cutover checklist reduces risk while keeping the work in-house.

How does a fixed-scope engagement handle changes and retesting?

DeployOpen agrees the scope, deliverables and timeline in writing before work starts, so the routing design, the endpoints covered, the environments tested and the cutover support are defined in advance. If a finding shows that the agreed scope is insufficient, for example because a federation path or a worker type was not in the original inventory, the change is raised in writing and the scope and price are revised before further work. Retesting after fixes is part of the written plan, so ask which tests are repeated, in which environment, and what evidence is delivered. Ongoing checks after upgrades are available as a retainer.

Does a Synapse routing change require a full outage?

Not necessarily. Routing changes are often rolled out by adding new worker pools behind the proxy, testing them with a subset of traffic, and then switching the map entries, which keeps the homeserver reachable during the change. Some changes, however, require restarting Synapse processes so that new worker configuration is loaded, and a change to the replication setup can affect every process at once. Ask the provider which steps require a restart, how long clients may see reconnects or failed syncs, and whether a rollback path exists that returns the proxy to the previous configuration without a database change. The answer depends on your topology and on the Synapse version, so confirm it against the upgrade notes for your release.

How DeployOpen scopes and delivers Synapse worker routing

DeployOpen plans the routing layer for Synapse sync and client traffic as part of a written, fixed-scope engagement, inside infrastructure you control. The work covers the worker map, the proxy configuration, the sticky routing rules and the tests that show each request type reaches the right process.

How we scope

  • Inventory current Synapse processes, listeners and traffic paths before choosing which generic workers to add
  • Agree in writing which endpoints, including sync, initial sync, login and event sending, route to which workers
  • Confirm the nginx or HAProxy platform, load balancer ownership and the Redis and PostgreSQL facts the design depends on

How we build

  • Write the worker configuration files and the nginx or HAProxy maps that send each request type to its worker
  • Keep replication listeners on a private network and restrict admin and replication endpoints at the proxy
  • Test sticky routing with real client sessions, including login, sync and message sending across two workers

How we hand over

  • Deliver the routing configuration, worker definitions and a runbook for changing the worker set
  • Document the sticky routing rules, the restart order and the rollback steps for each change
  • Walk your platform and operations teams through the monitoring checks that show routing is working

How we support

  • Offer ongoing support and upgrades as a retainer, including retesting routing after each Synapse upgrade
  • Review routing changes when user counts, room sizes or federation traffic shift, and update the written scope
  • Schedule continuous testing of the homeserver and proxy layer where your team wants it

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.