Building real-time software for TikTok LIVE creators
Over the past year I've built and run the software behind a network of TikTok LIVE creators who stream group shows: a cast of performers dancing, battling each other and playing games while viewers send gifts, likes and comments. Two systems run those shows: Glowstage ingests each live room's events in real time and turns them into games, goals and rankings on screen. Newstarhost is the operator's control room for songs, the cast, automation and analytics.
Both are in production every night. A single three-hour session can bring in over 12,000 gifts, a thousand comments and 175,000 likes, and every one of them has to reach the overlays within a fraction of a second and land in the database without slowing anything down. This post covers how they're built and what the data they collect shows.
| Glowstage | Newstarhost | |
|---|---|---|
| Role | Real-time event engine and on-stream widgets | Show control room and analytics |
| Stack | TypeScript: Node, Express, Socket.IO, React | Python: FastAPI, websockets |
| Data | Postgres on Supabase, shared event tables and SQL analytics functions | |
| Hosting | Fly.io, one always-on machine | Fly.io, deployed on every push |
Every widget below shows Glowstage's built-in example data, and the analytics are totals with no viewer names.
What Glowstage does
Glowstage connects to a live room and turns its events into things happening on screen. Every stage, ranking and widget is just a URL with a transparent background, added to TikTok LIVE Studio or OBS as a browser source. The operator arranges them into screens and sections of the show, and switches between them while live.
There are over 40 widgets in seven groups: gifts and goals, draws and raffles, arcade games, chat games, audience tools, rankings and utilities. A few of them:
And on real streams, with chat names and performer names blurred:
A few design choices held up. Each widget has a preview with example data, so a show can be built without going live. Themes apply across every widget, so a show looks like one thing rather than a collage. And every event is recorded, which is what makes the analytics below possible.
What Newstarhost does
Newstarhost started last year as a small FastAPI app for running dance battles and has grown steadily since. It holds the show's song library (375 songs, each with the length of the clip that's danced), the song queue, the cast, notes for each stream, gift assignments and automation, like a gift panel that runs on its own. State goes out over websockets to the overlays and the control panel, so every screen updates at once. It reads the live events Glowstage records instead of keeping its own connection to TikTok, and it deploys to Fly on every push.
Its analytics tab replaced a set of Grafana dashboards, with revenue, viewers and engagement by day, by time of day, by gift and by cast member.
How the data flows
Both tools run on one stream of events, so most of the design is about getting that stream in reliably and keeping it cheap to query.
Scroll sideways to see the whole diagram.
Ingestion
Glowstage's server is Node and TypeScript. For each live room it wraps an open-source TikTok LIVE connector and normalizes the feed into a handful of event types: gifts, comments, likes, follows and shares, joins, viewer counts and PK battles. The raw feed needs cleaning before anything else can trust it. TikTok re-sends messages after a reconnect, so events are de-duplicated by message ID for a minute. A gift combo arrives as a run of messages with a growing repeat count, so only the difference is passed on. When the connection drops mid-stream, it reconnects with exponential backoff (5 seconds, doubling up to 5 minutes) and keeps the same session; when the host ends the stream, the session is closed cleanly.
Live state
Every event goes to an engine that applies the active game's rules (a duel, a team battle, a gift challenge) to an in-memory state, which is kept separate from the show's saved configuration so that resetting a round never touches the settings. Each change is pushed over Socket.IO to every screen showing that part of the show. Widget state is broadcast at most every 150 ms, which is smooth on screen without flooding the browsers. Configuration goes through a normal REST API instead: it changes rarely and benefits from proper validation errors.
The database
Everything is recorded in Postgres on Supabase: a table per kind of event, plus sessions, check-ins, raffles, settings and accounts. The recorder buffers rows and writes them in batches once a second, and a failed write never blocks the event path, so a slow database can't make an overlay lag. Likes and joins are by far the largest and fastest-growing tables, so likes are stored as one row per viewer per minute instead of one per tap. Every chart counts likes by the minute at its finest, so nothing it shows changed, and the table got much smaller.
| Before: one row per like event | ||
|---|---|---|
| viewer A | 6:31:04 | ×1 |
| viewer A | 6:31:09 | ×3 |
| viewer B | 6:31:12 | ×5 |
| viewer A | 6:31:40 | ×2 |
| viewer A | 6:32:02 | ×1 |
| After: one row per viewer per minute | ||
|---|---|---|
| viewer A | 6:31 | ×6 |
| viewer B | 6:31 | ×5 |
| viewer A | 6:32 | ×1 |
Analytics
The analytics are a set of SQL functions in the database rather than an export to another tool: daily totals, time of day, sessions, gift mix, gifter levels, members, battles and sections. Each one takes a date range and an optional time-of-day window in Utah time, which is how the charts below are limited to the main show. Keeping them next to the raw events means a new question is one more function, with no pipeline to rebuild.
Newstarhost reads the same tables instead of keeping its own TikTok connection, so the two tools never disagree about what happened. On top, it adds its own records: songs played, stream notes and show sections. Every five minutes a job credits each song play with the diamonds gifted while it was on. Its analytics tab is built on the same functions.
Running it in production
A live show is unforgiving: if an overlay freezes or a gift goes uncounted, thousands of viewers see it and there's no second take, so a few decisions are there to keep it steady:
- Step 1 Stop signal A deploy or restart asks the old machine to shut down.
- Step 2 Close sessions Each open TikTok session is ended and its totals saved.
- Step 3 Flush buffers Every buffered row is written before the process exits.
- Step 4 Start fresh The new machine starts with the show's setup from Postgres, ready to reconnect.
- Glowstage runs on one always-on machine. The live connection, the Socket.IO rooms and the scores of a running game all live in that process's memory, so it's never scaled to zero or split across machines. Everything durable is in Postgres, so a restart loses nothing that matters.
- On a deploy or restart the server closes the open TikTok session and flushes buffered rows before it exits, so a deploy never loses events that were already received.
- The database is never on the hot path. Overlays are driven from memory; writes are batched, and a failed batch keeps its rows and retries on the next tick without blocking new events.
- Glowstage runs in San Jose next to the Supabase project, which keeps database round trips short.
- The game engines, tallying, combo handling and the recorder are covered by automated tests, because a scoring bug during a battle decides who wins a round viewers paid for.
What a month of analytics showed
One group's 30 days to August 26, filtered to the main show from 4pm Utah time onward: 11 days live, 4.1 million diamonds in gifts and a peak of 615 viewers. I've blurred the dollar figures in the screenshots.
Revenue is steady from day to day: the best day brought in about a quarter more than the median, and the weakest a little over half. Thursdays and Wednesdays were the strongest on average, Mondays the weakest.
Most revenue comes from a few large gifts
Four fifths of the money came from single gifts worth 1,000 diamonds or more, and the top two gift types, Sports Car and Interstellar, brought in nearly a third of what the top 15 earned. Gifts under 100 diamonds barely register in revenue. They still matter, because they're how a viewer starts taking part, but the show is paid for by a small number of large moments, which is why the games are built around big gifts unlocking big reactions.
Gifting comes in two waves
Viewers, likes and new joins all spike in the first half hour and the audience peaks near 380 by 4:20pm, then shrinks steadily. Gifting comes in two waves: one in the first hour, peaking around 4:50pm, and a second from about 6:40pm, after a trough around 6pm. The second wave happens with roughly half the audience of the first.
Money per viewer tells the same story more sharply. It's lowest in the busy first hour and climbs to about four times that level around 7:45pm, when fewer people are watching but they give far more each. Retention rises through the night too, from under four minutes to over six by the end: the people who stay late are the regulars. The early crowd is mostly browsers, so the first hour is for growing the audience and the second wave is where gift games pay off.
Stream length
Every live in this window ran close to five hours, so length explains little of the difference between days. The final hour added about a tenth of each live's revenue, consistent with gifting fading after 8pm.