messengerapi.Broker
An add-on service for Messenger API that adds inter-broker capability, making Messenger API resilient against outage. Runs as sidecar container with it's own DB, and periodically syncs Messenger databases between different instances to provide fallback capability for clients.
Why
Running single instance of message broker mean clients are left with no communication if the instance goes down for any reason at all. Adding secondary, or even tertiary instance of messenger to provide fallback option for clients is desirable. Broker runs in the background as a synchronizer of Messenger API databases. Messenger itself is completely unaware of this, while Broker keeps track of what entities injected into Messenger's database are foreign.
How
Broker runs 3 tasks endlessly for each server it's supposed to provide resiliency for:
- User and UserRoute synchronization periodically (typically every 1 minute).
- Message synchronization (fast) - endless queries to provide all messages for last short period of time (typically last 10 seconds).
- Message synchronization (slow) - endless queries to provide all messages for entire visible history of garbage collection. This process runs typically every 10 minutes and serves to collect missed updates, deliveries, and acknowledgements.
To prevent clogging, Broker will only provide 1000 records per request, so synchronizing Broker has to provide a time argument for where to start the lookup. You can see this here.
Auth
Broker uses it's own unique Broker ID to authenticate itself and others. All exposed endpoints expect this ID to be sent over as part Bearer token in Authorization header. Each Broker is configured for a list of servers that are expected to pull, and list of server that the Broker itself is supposed to pull from. Bearer token is then compared against that list during each call to make sure only allowed Brokers consume resources.
Endpoints
Endpoints listed here are consumed by other Brokers.