Skip to content

Commit e1cd6be

Browse files
committed
documentation about synapse workers
1 parent 1f0941e commit e1cd6be

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,75 @@ helm repo add code-tool https://code-tool.github.io/matrix-stack/
2222
## Visualisation
2323

2424
![Matrix home servers setup overview](overview.png)
25+
26+
## Synapse worker architecture
27+
28+
The core of synapse monolith distribution is complex regexp routing to particular workers.
29+
30+
Worker types
31+
32+
### synapse.app.generic_worker
33+
34+
Most common worker type: can read data, respond to HTTP API, client and federation requests. Has no streams and cannot write any stream by itself.
35+
36+
A generic worker can be:
37+
- reader - client_reader, federation_reader, sync, room
38+
- stream writer - if configured in the stream_writers section
39+
- both simultaneously
40+
41+
generic_worker is not an architecture type - it is a behavior type determined by config.
42+
43+
### Stream writer
44+
45+
Not a separate app type - this is a role for a generic worker when it is listed in stream_writers. The stream writer owns a Redis stream exclusively; other workers write to that stream by
46+
sending HTTP requests to it.
47+
48+
Requirements:
49+
- must be in instance_map
50+
- must have a replication listener (port 9093)
51+
52+
Singleton streams (one writer only): typing, to_device, account_data, presence, push_rules
53+
54+
Scalable streams (round-robin across multiple writers): receipts, device_lists, thread_subscriptions, quarantined_media, events
55+
56+
### synapse.app.media_repository
57+
58+
The only distinct worker app type, different from generic_worker:
59+
- uses media-specific headers
60+
- responds to /_matrix/media/, /_matrix/client/v1/media/, /_matrix/federation/v1/media/
61+
- can have a background job: media_instance_running_background_jobs
62+
- cannot be a stream writer
63+
- cannot respond to any client/federation endpoints
64+
65+
### Background jobs
66+
67+
Generic workers with no HTTP endpoints:
68+
- background - singleton; stats, media cleanup, user directory updates
69+
- pusher - pusher_instances: [pusher1, pusher2]; sends push notifications
70+
- federation_sender - federation_sender_instances: [sender1, sender2]; outbound federation only
71+
72+
Worker reference table
73+
74+
--------------------------------------------------------------------------------------------------------
75+
| worker | type | scalable | possible lb algo | http |
76+
--------------------------------------------------------------------------------------------------------
77+
│ typing │ stream writer │ no │ - │ yes |
78+
│ to_device │ stream writer │ no │ - │ yes |
79+
│ account_data │ stream writer │ no │ - │ yes |
80+
│ presence │ stream writer │ no │ - │ yes |
81+
│ push_rules │ stream writer │ no │ - │ yes |
82+
│ receipts │ stream writer │ yes │ round-robin │ yes |
83+
│ device_lists │ stream writer │ yes │ round-robin │ yes |
84+
│ thread_subscriptions │ stream writer │ yes │ round-robin │ yes |
85+
│ quarantined_media │ stream writer │ yes │ round-robin │ yes |
86+
│ events (persister) │ stream writer │ yes │ shard by room_id │ yes |
87+
│ media_repository │ app │ yes │ least_conn │ yes |
88+
│ media_instance_running_background_jobs │ app │ no │ no │ no |
89+
│ room_worker │ generic │ yes │ hash by room_id │ yes |
90+
│ sync_worker │ generic │ yes │ hash by user_id │ yes |
91+
│ federation_reader │ generic │ yes │ hash by source ip │ yes |
92+
│ client_reader │ generic │ yes │ least_conn │ yes |
93+
│ user_dir │ generic │ no │ - │ yes |
94+
│ background_worker │ generic │ no │ - │ no |
95+
│ pusher │ generic │ yes │ shard by user │ no |
96+
│ federation_sender │ generic │ yes │ shard by destination │ no |

0 commit comments

Comments
 (0)