← All posts

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.

GlowstageNewstarhost
RoleReal-time event engine and on-stream widgetsShow control room and analytics
StackTypeScript: Node, Express, Socket.IO, ReactPython: FastAPI, websockets
DataPostgres on Supabase, shared event tables and SQL analytics functions
HostingFly.io, one always-on machineFly.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:

Gift menu widget: Reset points, unlocked by a Cosmic DJ gift worth 500 diamonds.
Gift menu: each gift unlocks something on stream.
Gift challenge widget: a countdown at 4:55 and a progress bar at 333 of 1,000 diamonds, 667 to go.
Gift challenge: a timed diamond goal.
Lucky wheel widget with four segments: Freestyle, Runway, Random effort and Random filter, in a casino-style gold and red frame.
Lucky wheel: gifts spin it to pick what happens next.
Slot machine widget showing 500 points to spin, with a result card awarding Alice a shout-out.
Slot machine: points earned by gifting buy a spin.
Poll widget asking Which song next, with two options at 37 and 17 votes.
Poll: the chat votes on the next song.
Like ranking widget listing the top three likers with gold, silver and bronze crowns.
Like ranking: the top likers, live.

And on real streams, with chat names and performer names blurred:

A group live from Lunova: seven performers dancing on a pink-lit stage, with a countdown timer at 9:44, a member ranking panel and the chat. Chat and performer names are blurred.
A Lunova group live: a countdown timer, a member ranking and a cast list on stage.
A Wildcardz live with a gift challenge at 430 of 2,000 diamonds and 24 seconds left, a slot machine, a gift menu, house rules, a score list and a like ranking. Chat and performer names are blurred.
A Wildcardz live: a gift challenge, slot machine, gift menu and like ranking, all at once.

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.

Newstarhost's Song Selection tab: a front-dancer filter (names blurred), Camera and Play Suggested buttons, and a searchable grid of 375 songs, each showing its title, the length of the danced clip and the artist, with a play button.
The Song Selection tab: 375 songs, each with the length of its danced clip, filterable by who's in front. Dancer names are blurred.

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.

Glowstage and Newstarhost architecture TikTok LIVE rooms send events to the Glowstage server, where a connector cleans them, an engine applies the show's rules and pushes state over Socket.IO to the on-stream widgets, and a recorder writes batches to Postgres on Supabase every second. Postgres holds the event tables and the analytics SQL functions. Newstarhost reads the events and analytics from Postgres and writes songs, notes and show sections back. TikTok LIVE one feed per room GLOWSTAGE SERVER · NODE Connector dedup, combo deltas, reconnects Engine game rules, in-memory state Recorder buffers rows, never blocks On-stream widgets browser sources in TikTok LIVE Studio or OBS POSTGRES · SUPABASE Event tables gifts, likes, joins, battles… Analytics functions by day, time, gift, member Newstarhost · FastAPI control panel, songs, analytics tab events Socket.IO ≤150 ms batches, 1 s reads events, analytics writes songs, notes

Scroll sideways to see the whole diagram.

How events move from a TikTok LIVE room to the screen and into the database. Both tools read the same tables.

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.

Example of four raw TikTok messages for one gift combo. Message 41, combo times 1, becomes plus 1 Rose. Message 42, combo times 3, becomes plus 2. A re-sent copy of message 42 after a reconnect is dropped because its ID was already seen. Message 43, combo times 5, becomes plus 2. The total is 5 Roses, counted once. TikTok sends Glowstage emits msg 41 Rose, combo ×1 +1 Rose msg 42 Rose, combo ×3 +2 Rose msg 42 Rose, combo ×3 (re-sent after reconnect) dropped: seen this ID msg 43 Rose, combo ×5 +2 Rose Total: 5 Roses
An example combo. Each update carries the running count, so Glowstage emits only the change, and a message re-sent after a reconnect is dropped by its ID. The total is right even if TikTok never sends the combo's final message.

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.

Timeline from 0 to 1,000 milliseconds. 17 events arrive in bursts; the widget state goes out 7 times, never more than once every 150 milliseconds, each update carrying every change since the last. 0 ms 250 ms 500 ms 750 ms 1000 ms Events in Updates out event at 20 ms event at 32 ms event at 41 ms event at 55 ms event at 180 ms event at 186 ms event at 195 ms event at 204 ms event at 212 ms event at 430 ms event at 436 ms event at 700 ms event at 706 ms event at 712 ms event at 719 ms event at 725 ms event at 890 ms update at 20 ms update at 170 ms update at 320 ms update at 470 ms update at 700 ms update at 850 ms update at 1000 ms
An illustrative second: 17 events in bursts become 7 updates. Each update carries every change since the last, so the overlays never fall behind and the browsers aren't flooded.

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 A6:31:04×1
viewer A6:31:09×3
viewer B6:31:12×5
viewer A6:31:40×2
viewer A6:32:02×1
After: one row per viewer per minute
viewer A6:31×6
viewer B6:31×5
viewer A6:32×1
An example of how likes are stored. Every chart counts likes per minute at its finest, so merging them per viewer per minute changes no result and shrinks the largest table.

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:

  1. Step 1 Stop signal A deploy or restart asks the old machine to shut down.
  2. Step 2 Close sessions Each open TikTok session is ended and its totals saved.
  3. Step 3 Flush buffers Every buffered row is written before the process exits.
  4. 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.

Analytics filtered to 4pm Mountain Time onward, July 28 to August 26, 2026. Bar chart of estimated revenue per stream day across 11 live days from August 10 to 26, fairly even with the highest day about a quarter above the median. Totals above: 4.15 million diamonds, 11 live days and 615 peak viewers; dollar figures are blurred.
Estimated revenue per stream day from 4pm onward, July 28 to August 26, dollar figures blurred.

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

Left: the 15 gifts that brought in the most money, led by Sports Car, Interstellar, Galaxy and TikTok Universe. Right: revenue by gift size; gifts of 1,000 diamonds or more bring in about four fifths of the total. Dollar figures are blurred.
Which gifts paid, and revenue by the size of a single gift.

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

Four charts by time of day from 4pm. Gifts per minute peak at about 17 around 4:50pm, fall to about 3 around 6pm, then rise to a second peak of about 13 around 6:50pm before tapering after 8pm. Viewers climb to about 380 within twenty minutes and decline to about 170 by 8pm. Likes and joins per minute are highest in the first hour and decline through the evening.
By time of day from 4pm, averaged over the 30 days: gifts, viewers, likes and joins per minute.

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.

Two charts by time of day from 4pm. Money per viewer-minute is low through the first hour and peaks around 7:45pm at about four times its early level, then falls after 8:15pm. Average retention rises from under 4 minutes to over 6 minutes by the end of the night. The money axis is blurred.
Money per viewer each minute (axis blurred), and how long the average joiner stays.

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

Left: a scatter of each live's length against revenue; every live ran between about 4 hours 58 minutes and 5 hours 10 minutes. Right: revenue in each live's final hour stacked on the rest, about a tenth of the total. Dollar figures are blurred.
Left: hours live against revenue for each live. Right: what the final hour added.

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.