When event persister sharding is the right next step for Synapse
Event persister sharding is worth planning only when your Synapse main process is the measured write bottleneck. The main process normally persists every event to PostgreSQL and publishes it to the rest of the deployment. When that single writer falls behind, clients see slow message delivery and rising latency on event sending, and the fix is to hand part of that persistence work to dedicated event persister workers. Before you change anything, confirm the constraint. Sync latency, federation backlog and a slow database can each produce similar symptoms, and adding persisters will not help if the problem sits in one of them. Check the main process CPU and its replication lag, the sending and sync latency for your heaviest rooms, and the PostgreSQL query and lock timings during peak hours. Add the Synapse worker and metrics documentation to your reading list, and confirm with your platform team which of these signals you already collect.
Once writes are the constraint, the mechanism is the stream_writers setting in the worker configuration. It tells Synapse which worker is responsible for writing each event stream, such as events, and which worker should persist events. With stream_writers set to more than one worker, Synapse divides rooms among the listed event persisters, so each room's events are always written by the same process. That fixed assignment keeps event ordering consistent within a room. Splitting writes also changes how replication flows through Redis, so the design has to be tested against your own room mix rather than copied from a sample config. Ask your Synapse operator or partner to show the planned instance_map and the expected load on each persister before you commit to a count.
Treat the decision as a planned change with a rollback path. Changing the persister set alters the room-to-worker mapping, and every worker in the deployment must restart so it picks up the new assignment, so schedule a maintenance window and measure how long a full restart takes in staging. Record the baseline write latency, the main process load and the database connection count first, then compare them after the change. If the numbers do not move, the bottleneck was elsewhere, and a persister set that is larger than needed only adds restart cost and operational overhead. Make sure the Synapse release you run supports the worker layout you plan, and read the upgrade notes for that release before touching the configuration, since rollback after schema changes can be difficult.
Stream writer configuration options and when each fits
This table compares three ways to lay out stream_writers for event persistence: keeping events on the main process, running one dedicated persister, and running several persisters that share rooms. Read each row as the cost of moving from one layout to the next, and treat the main takeaway as a rule of thumb: add persisters only after write load on the main process is measured, because every added persister widens what restarts on a change.
| Layout | Replication and write load | Restart scope and operational complexity | When it fits |
|---|---|---|---|
| Events persisted by the main process | All event writes and stream positions pass through one process. Replication traffic stays simplest because no other process writes to streams. | Only the main process restarts for configuration changes. There is no room-to-persister mapping to maintain or verify. | Small or moderate write volume where monitoring shows the main process has headroom. This is the default starting point. |
| One dedicated event persister | Event persistence moves off the main process, but all writes still funnel through a single writer. Replication load on Redis rises because the persister publishes its own stream positions. | A change to the persister restarts that worker and the processes that depend on its stream. Configuration is a single named instance, so the mapping is easy to audit. | Main process write latency is the measured bottleneck and one persister has enough capacity. Good for a first step before sharding. |
| Several persisters with a shared room split | Writes spread across persisters by room, which raises total write capacity. Each persister publishes stream positions, so Redis replication and cross-process coordination grow with the count. | Adding, removing or renaming a persister in the set restarts every worker, so changes need a planned window. The room-to-instance mapping must be kept identical across all processes and reviewed on every change. | Measured write saturation persists even after moving to one dedicated persister. Teams should confirm their monitoring and change process can support a coordinated restart before choosing this layout. |
Setting up event persister workers in order
This sequence moves event persistence off the main Synapse process and onto dedicated event persister workers. It ends with one configuration that every process agrees on, a planned restart, and evidence that the persisters are taking write traffic from the main process.
Confirm Redis and the replication listener
Confirm that the main process and every planned worker can reach the Redis instance that relays replication between processes. Check the Redis authentication settings and the replication secret on each host, and confirm that the replication listener is bound to a private interface that clients cannot reach. Run a connection test from each host to verify the network path. Done when every host connects to Redis and the main process logs a healthy replication listener.
Plan the persister set and record a baseline
Decide how many event persisters to run and list each one by its planned worker_name and host. Each persister takes a share of rooms, so the list you choose determines which process owns writes for which rooms. Confirm the sharding behavior in the Synapse workers documentation before you finalize the list, and keep the list stable because changes later reroute every affected room. Record current write latency as a baseline. Done when the team signs off a written list that matches the provisioned hosts and the baseline is saved.
Define each persister worker file
Create one YAML file per persister. Each file needs a unique worker_name and a worker_type set to event_persister, along with the listener and replication settings from your Redis and network plan. Name the files predictably, such as one per worker_name, and store them with the rest of the Synapse configuration so reviewers can compare them. Done when each file parses as valid YAML and every worker_name matches the plan from the previous step.
Update stream_writers and instance_map on the main process
Add the persister names to stream_writers for the streams they will persist, and map each worker_name to its replication address in instance_map. Keep the main process in the map, because streams not listed under stream_writers stay on the main process. Use the worker names exactly as they appear in the YAML files. Test the change on a staging copy of the main process configuration. Done when the main process starts with the new configuration and reports no unknown instance names.
Apply the same map to every worker
Copy the identical stream_writers and instance_map blocks into the main process file and into every persister and generic worker file. All processes must agree on which instance owns which stream. Compare the files with a diff before deploying, so that the only differences are settings meant to vary per host, such as worker_name and listener details. Done when the diffs show only those intended differences across all hosts.
Restart processes in a planned order
Schedule a maintenance window, notify users, and restart processes in the order your runbook specifies. Expect every worker to restart when the stream set changes, not only the new persisters. The Synapse workers documentation describes why the configuration must be consistent across the deployment. Watch each host's logs as its processes come back. Done when every process reports a connection to replication and no process logs errors about unknown streams or instances.
Verify replication and write latency
Confirm that the persisters receive write traffic and that the main process no longer persists events for the streams you moved. Review the Synapse metrics for event persistence and compare write latency with the baseline recorded earlier. Send test messages to rooms that different persisters own, and confirm they reach local and federated clients. Done when test rooms deliver messages, latency is at or below baseline, and a named owner is assigned to ongoing monitoring.
Why every worker restarts when the persister set changes
Adding, removing or renumbering an event persister changes the shared stream writer layout that every process reads at startup. The consequences below affect uptime, in-flight requests and the change window, so they should be planned before the configuration is edited.
Shared layout forces a full restart
The stream writer assignments in the shared configuration must match on every process. When you change which worker writes which stream, the main process and all workers must be restarted together, not one at a time. Treat the persister list as a single versioned configuration change that is deployed to every node in the same window. Check that each worker's config file is identical in the stream writer section before you start the rollout.
Synapse workers docsClient sessions drop during the window
Restarted processes close their open connections, so long-running /sync requests and active client sessions are interrupted and must reconnect. Clients usually retry automatically, but users may see delayed messages or a brief sync stall. Measure how many clients are connected at peak and confirm with your Element or other client vendors how they handle reconnects. Plan the window for the lowest-traffic period your users actually experience.
Federation traffic queues and retries
Remote servers that send events to your homeserver will see connection failures while the federation receiver restarts. Most federating servers retry outbound transactions over time, but events may arrive late and room state can briefly lag. Confirm that the federation listener on port 8448 and any delegated endpoints come back cleanly after restart. Review federation logs after the window for repeated failures from specific peers.
Stream positions must stay consistent
Replication uses stream positions to tell each process what has been written. A restart that starts a persister with the wrong stream assignment can leave a stream without a writer or with two writers, which causes missing or duplicated updates. Before the rollout, confirm that every stream listed in the stream writers configuration has exactly one owner. Run a test deployment with the same layout to check that all processes reach a healthy state.
Rollback is harder than the change
Reverting to the previous persister layout means another full restart and a second wave of reconnects. Keep the previous configuration files ready and record the exact order in which processes were restarted. Because Synapse upgrade notes warn that rolling back can be difficult after schema changes, do not combine a persister change with a version upgrade in the same window.
Schedule a documented change window
Agree the window with the business owners of the homeserver, announce it to users and federation partners, and assign one person to drive the restart sequence. Restart processes in a documented order and check replication and client login after each stage. Confirm with your team which monitoring signals mark the change as complete before you start.
Confirming the main process is the write bottleneck
Before you add event persisters, confirm that the main process is actually the constraint. Sharding is the wrong fix for slow sync, slow federation or an undersized database, and each of those symptoms can look like a busy main process from the outside. Write saturation shows up as persistence work queuing behind a single process, while the other failure modes point at different components. Start by separating them, because the remedy for each is different and a persister set adds a restart cycle to your change calendar.
On the main process, measure how busy it is and where its time goes. Use the Synapse metrics endpoint and the monitoring guidance in the Synapse documentation to track event persistence time, the backlog of events waiting to be persisted and the process's CPU and event loop load over normal and peak periods. Compare these with the same measurements on the database side: PostgreSQL lock waits, long-running transactions, connection pool saturation, disk I/O and replication lag if you run replicas. If PostgreSQL is waiting on the database and not on Synapse, more persisters will not help. Confirm the exact metric names against your Synapse version, since they change between releases.
Also check the paths that are not writes. Federation backlogs, slow /sync responses and heavy joins to large remote rooms each have their own signals and their own workers, covered in sibling sections. Record a dated baseline of the workload that is slow, including which rooms and which kinds of traffic dominate it. Persister work is justified when the evidence shows sustained persistence delay on the main process, with the database healthy and the other paths unremarkable. Ask your partner or internal team to write down that evidence before any change is approved, so the case for sharding can be reviewed later.
How writes flow through the main process, Redis and event persisters
The diagram starts with clients and federated servers reaching generic workers, which send writes to event persister workers named in stream_writers. Persisters write to PostgreSQL, the shared store, and announce new events over Redis replication to the main process and other workers. Check that the replication listener sits on a private network, since Redis and worker replication traffic should never be exposed publicly.
Writes route from generic workers to event persisters, with Redis carrying replication.
Security and operational considerations for persister workers
Adding event persisters puts more processes on the write path and more configuration in the open. The cards below cover network exposure, the shared replication secret, configuration drift across hosts, and the limits on backing out an upgrade once the schema has changed.
Keep the replication listener private
Each persister exposes a replication listener that the main process and other workers connect to. Bind it to a private interface or a restricted subnet, and never publish it through the reverse proxy. Confirm that your firewall rules allow only the Synapse hosts and the Redis endpoint to reach it. Test this from outside the network, not only from inside the configuration files.
Synapse workers docsProtect Redis as the replication bus
Redis relays replication traffic between the main process and every persister, so a compromised or open Redis instance exposes the whole event stream. Require authentication, keep Redis off public networks, and limit which hosts can connect. Ask your platform team who owns Redis availability, because a Redis outage stops event persistence across all workers at once.
Manage the shared replication secret
Workers authenticate to the main process with a shared replication secret set in the Synapse configuration. Store it in your secrets manager, inject it at deploy time, and rotate it by restarting every process in one change window. Do not paste it into shared configuration templates or chat channels. Record who can read the secret and where each copy lives.
Keep configuration identical across hosts
Every persister must agree with the main process on the worker list, stream writer assignments, and the server name. A host with a stale file can claim a room shard that another process also claims. Generate worker configuration from one source, check file hashes after each deploy, and make a set change a planned operation rather than an edit on a single box.
Plan for the rollback limits
The Synapse upgrade notes warn that rolling back can be difficult because releases change the database schema. Take a verified PostgreSQL backup before each upgrade, read every set of notes between your current and target versions, and rehearse restoring that backup. Assume that a worker-layout change combined with a schema change may only move forward.
Synapse upgrade notesCoordinate restarts when the set changes
Changing the set of event persisters restarts every worker, so the change is an outage-sized event for the whole homeserver. Schedule it, notify users, and confirm that the load balancer drains connections before restarts begin. Include the rollback steps in the change record so the on-call engineer does not have to rebuild them under pressure.
Questions teams ask before adding event persisters
Should we add event persisters before other Synapse workers?
Usually not as a first step. Event persisters address write pressure on the main process, so the first question is whether writes are the bottleneck or whether sync, client traffic, federation or background jobs are. Teams typically move client and federation traffic to generic workers first, because that work is simpler to route and verify. Confirm the bottleneck with your own metrics before you split writes, since a persister set adds a restart point every time its membership changes. The Synapse workers documentation describes the worker types, and the sibling topic on moving from a single process helps with that order.
What drives the effort and cost of adding event persisters?
Effort comes from four areas: staff time to analyze load and choose the split, Redis and PostgreSQL work to connect the new processes and confirm connection limits, configuration and routing changes, and monitoring and testing. The cost is mostly people time and the infrastructure you add, both one-time for the initial change and recurring for upkeep. Costs rise with the number of persisters, the size of your federation footprint, and how many environments need the same change. Ask any provider to split the quote into analysis, configuration, testing, runbook and handover, so you can see what is one-time and what your team will maintain.
How long does adding event persisters take?
The duration depends on topology more than on the configuration itself. A single-host deployment with one Redis instance and one PostgreSQL database is simpler than a split across machines, a container platform or a high-availability database cluster. Time also depends on how much load analysis is needed, whether a staging environment mirrors production, and how many change windows your organization allows. No fixed duration applies across these setups. Ask for a timeline tied to your topology, and confirm which steps need a maintenance window.
What must our team provide before the work starts?
Plan to provide access to a staging copy of the homeserver, the current Synapse version and configuration files, database and Redis details, and metrics or logs covering write latency and the main process load. You will also need a named owner who can approve change windows, and someone who knows your reverse proxy and network rules. Confirm who holds credentials for PostgreSQL and Redis, and whether the replication listener is reachable only on a private network. Missing inputs are the most common cause of schedule slips in this kind of work.
Can our own platform team add event persisters without a partner?
Yes, if your team already operates Synapse, PostgreSQL and Redis and can test changes in staging. The change touches the worker configuration, the replication setup and routing, and every worker restarts when the persister set changes, so the work needs careful rollback planning. Teams without recent experience with Synapse workers often benefit from an outside review of the plan before production. DeployOpen can plan, implement and document this change in infrastructure you control, with the scope agreed in writing before work starts.
Does adding event persisters also need Synapse Pro or ESS Pro?
Not for this change alone, since event persisters are configured in community Synapse through stream_writers and instance_map. Compare Synapse Pro or ESS Pro when your deployment is outgrowing hand-tuned workers and you need features such as autoscaling or multi-tenancy. Licensing is a separate question: Synapse is distributed under AGPL-3.0, and Element sells commercial licenses, as described in its ESS overview. Ask Element for written terms before you assume which features are included.
What should we check after the persisters go live?
Check that each persister handles the rooms assigned to it, that write latency on the main process drops as expected, and that replication lag stays within your own target. Verify restarts after a worker set change, confirm that sync and message delivery work for users across shards, and review logs for replication errors. Keep a documented procedure for adding or removing a persister, since the restart behavior is the main operational risk. Ask any partner to hand over this runbook along with the test results.
How DeployOpen scopes and delivers Synapse worker scaling
Event persister sharding is delivered as a fixed-scope engagement. Before any work starts, DeployOpen and the client agree in writing on the current topology, the target set of stream_writers entries, the Redis and PostgreSQL changes, the monitoring that will show whether the change helped, and the acceptance tests. The written scope also names the restart window, because changing the persister set restarts every worker, and the client's change board needs that date and impact statement before the work is scheduled. A quote follows from this scope, so the client can compare it with the cost of doing the work with its own team.
During planning, DeployOpen reviews the homeserver in the client's own infrastructure: the database write load, the Synapse version and its upgrade notes, the worker processes already running, and how traffic reaches the listeners. The implementation then sets up the persister workers, the replication configuration and the routing in a staging environment that mirrors production, followed by a rehearsal of the restart. Every change is documented with the exact configuration keys, the process layout and the rollback steps, so that the client's platform team can operate the deployment without the implementer. Confirm with the client's own change process how long the restart window must be before the scope is signed.
Testing and handover close the engagement. Testing checks that messages persist in every room shard, that replication lag stays within the agreed limits under load, and that clients and federation traffic recover cleanly after a restart. The handover covers the runbook, the monitoring dashboards and a walk-through with the operators. Because Synapse ships upgrades that change the worker layout and database schema, many clients choose a retainer for ongoing upgrades and continuous checks after each release. Retainers are arranged separately from the fixed-scope project, and their terms are set out in their own written agreement.

