How chat flows
This page is for owners who want to know why chat behaves the way it does. After reading it you can follow a message from where it is typed to every screen that shows it, and you know which checks it passes on the way.
Your site shows chat from every platform you stream on, plus its own site chat, as one list. What viewers see and do in chat is in Chat.
The short version
flowchart LR
T[Twitch / Kick / YouTube / Streamplace chat] --> I[stream-ingest]
I --> A[stream-api]
B[Viewer typing on your site] --> W[web]
W --> A
A --> DB[(database)]
A -- WebSocket --> S[Every open page and overlay]
Every message, wherever it was typed, ends up at stream-api (the chat service). stream-api decides who sent it, runs the checks, stores it and sends it to everyone over one WebSocket. Nothing reaches chat any other way, so every screen sees the same messages in the same order.
A message from a streaming platform
1. stream-ingest reads it
stream-ingest (the ingest service) keeps a connection open to each platform you have set up and reads chat as it arrives. Each platform describes a message differently, so stream-ingest turns each one into the same shape: the platform, the sender's id and name there, the text, the platform's own id for the message, the sender's badges (mod, VIP, member, subscriber tier), their name colour, any emotes, and, for a reply, who and what it replies to.
It then sends the message to stream-api. Delivery comes first: it has its own queue with several workers and room for a long backlog, so a burst of chat loses nothing. The slower extras, such as the AI features and memory, run in a second, smaller queue that is skipped when delivery falls behind. If deliveries keep failing, stream-ingest raises the alarm "Chat not reaching stream-api".
Your list of known bot accounts (Bot usernames, in Admin Panel → AI → Chat Bot, card Accounts) is checked here, so a bot's messages are marked as a bot's.
2. stream-api checks it, in this order
| Step | What happens | Why it is here |
|---|---|---|
| Lockdown | If that platform's chat is paused by lockdown, the message is dropped before anything else | Nothing from a paused platform should be stored or counted |
| Who sent it | The sender is matched to one person, or a new person is made. See One person, many accounts | Everything after this is about a person, not a platform name |
| Echo check | If this is a copy of a message your own site posted moments ago to that platform, it is dropped (see Send to all and echoes) | A message sent from your site shows once, not once per platform |
| Poll vote | While a poll runs, a message that is only the number of one of its options counts as that person's vote and stops here: it is not stored, shown or sent to overlays. Typing another number moves the vote. A number that is not an option is an ordinary message | Viewers on any platform can vote by typing, and a bare number in chat a second before the tallies move would tie a voter's accounts together |
| Reply | If the platform says the message replies to someone, stream-api finds that earlier message in recent chat and links the two | A reply on Twitch to a site message points at the right line |
| Word filter | A message that matches the word filter is not shown and not stored. It is logged for your mods instead | A starred-out word is still read by everyone, and a stored one would come back in history and teach the bot |
| Link rules | A message with a link your link rules do not allow is held for review (or, in flag mode, shown and flagged) | Links are the main tool of spam and scams |
| Account age | If a minimum account age is set, a message from a newer account is held | Raids often use freshly made accounts |
| Pronouns | A plain statement such as "my pronouns are they/them" is saved for the sender | See Pronouns |
A message stopped here still exists on the platform it was typed on. Removing it there is that platform's own moderation. What your site gives your mods is the record, so they can act on the sender everywhere.
When a mod releases a held message, it goes through the same checks again, skipping only the one that held it. The word filter always runs again, so releasing a link cannot slip a filtered word through.
3. stream-api stores it and sends it out
The message is written to the chat log together with the stream it belongs to. In the same step stream-api learns whether this is the sender's first message ever, which shows as a "first message" mark.
Then stream-api sends it to every connected screen and adds it to a list of the last 200 messages it keeps in memory.
A message typed on your site
When a signed-in viewer sends a message on your site:
- The browser sends it to the website.
- The website runs its own checks: the sender's rate limit, the character limit, the word filter, link rules, bans and timeouts, slow mode and subscriber-only mode, and, if automod is on, an AI check that can hold the message for a mod. These run on the website because only the website knows who is signed in, their tier and their roles.
- The website passes the message to stream-api, signed with the shared secret.
- If a poll is running and the message is only an option's number, stream-api counts it as a vote and stops. Nothing is stored or shown, and the sender sees "Counted as a vote for option 2". If the vote could not be saved, they are told it was not counted and to try again.
- Otherwise stream-api stores the message in the site's own message table, sends it to every screen and adds it to the last-200 list. It refuses to send a message it could not store, because a message on screen with nothing behind it would vanish for some viewers and come back for others.
- After the message is out, stream-api also writes a copy into the chat log, so the bot's view of recent chat and its memory include site chat. Chat history leaves these copies out, so nothing shows twice.
The site's own platform: native
Every message has a platform. A message typed on your site has the platform id native, in every install. Viewers never see that word: wherever a platform name is shown, the site shows your site's name instead. The same id marks payments made on your site and the link between a site account and a person.
Send to all and echoes
A viewer with linked platform accounts sends each message to your site and to those platforms at once, unless they pick something else in the send-to menu (All linked platforms is the default; see Linking your platforms). The website posts the message on each platform as that viewer, with the account they linked, and shows one line on your site. If a platform refuses, the line stays on your site and the sender sees "Posted here", followed by which platform refused and why, in that platform's own words. A network or server hiccup on the way is not shown to the sender.
Each platform then shows the message in its own chat, so a few seconds later stream-ingest reads it back like any other message. Without a check, the message would show on your site once for every platform. stream-api catches these copies in three ways, strongest first:
| How | Kept for | How it works |
|---|---|---|
| By message id | 10 minutes | When a platform accepts the post, it returns its own id for the message. The website hands those ids to stream-api, and an incoming message with one of them is the copy. Works for Twitch, Kick and Streamplace |
| By sender | 2 minutes | The copy comes back from the viewer's own platform account, which the site knows from the link. A matching text from that account is the copy |
| By text | 20 seconds | A matching text from a platform the message was sent to. Only as many copies as were expected are dropped, so another viewer who types "lol" at the same moment is not swallowed |
Your site reads YouTube chat. Posting from your site into YouTube chat is where the work is going next, so for now a message sent to all goes to your site and the viewer's linked Twitch, Kick and Streamplace accounts.
When a page connects: history
When a page opens a WebSocket to stream-api, stream-api first sends the last 200 messages in one go, then the current state of the timer and other live parts, then everything new as it happens. That is why an OBS overlay that reloads mid-stream shows chat again at once.
The site's chat also loads a page of older history from the database when it opens, and loads more as you scroll up. The two are matched by platform and message id, so a message that is in both shows once.
A page whose connection goes quiet without closing drops it after 90 seconds and connects again, which brings the last 200 messages back with it.
The 200-message list lives only in stream-api's memory. After stream-api restarts it starts empty and fills again as people chat. The database history is not affected.
What the public WebSocket carries
The WebSocket on api.example.com is open to anyone, because overlays and signed-out visitors need it. It only sends: anything a page sends back is ignored, apart from keep-alive replies. It carries what is already public in chat, with one change: each message carries the sender's public id, which differs per platform, never their internal person id. See Why links are private.
The website's server and stream-ingest connect to the same WebSocket with the shared secret. Those internal connections also get the internal ids and control messages such as "a setting changed", which no browser ever receives.
To keep one visitor from using up the server, stream-api limits open connections: 5,000 in total and 32 from any one address (one OBS computer often runs a dozen overlays). A connection that stops reading is closed once 1 MB is waiting for it, and one that stops answering keep-alive pings is closed within a minute.
Next: Sign-in and accounts