How it works
How monedula-sim-bridge relays Kafka requests to the playground tab, why the tab is the broker, how ticks pace the cluster, and why you opt in each time.
On this page
The bridge does not simulate anything. It speaks the Kafka protocol to your clients and relays every request to the playground tab, where the Kafka Simulator’s engine answers it. The tab is the cluster; the bridge is its network.
Two halves
| Part | Where it runs | What it does |
|---|---|---|
monedula-sim-bridge |
Your computer, on 127.0.0.1 |
Opens one Kafka port per live simulated broker, decodes requests, decompresses produced batches, answers ApiVersions and the three ACL APIs itself and forwards the rest as JSON over a WebSocket. |
| The playground tab | Your browser | Answers each request from the simulated cluster: leaders, offsets, groups, configs. Shows your clients on the canvas as apps. |
The two agree on a small protocol of JSON messages. The bridge and the playground each check its version when they pair, and a mismatch is refused with a message to update monedula-sim-bridge.
Pairing
- The bridge starts, picks a random six-character pairing code and listens for the playground on
ws://127.0.0.1:19190/. - You press Connect in the playground’s Connect your apps panel. The tab opens the WebSocket and sends the code.
- The bridge checks the page’s origin and the code. On a match it welcomes the tab; otherwise it refuses and closes the socket.
- The tab sends the cluster: its brokers, which are alive, and the controller. Only now does the bridge open the Kafka ports, broker N on 19092 + N - 1, and it sends the cluster again whenever a broker is added, killed, restarted or removed.
A request
A client connects to a broker’s port and sends, say, a Produce request. The bridge decodes it, decompresses gzip, snappy, lz4 and zstd batches, and sends the records to the tab, tagged with the broker the client chose. The tab answers as that broker: if it does not lead the partition, the answer is NOT_LEADER_OR_FOLLOWER, exactly what a real broker sends. The bridge encodes the answer in the version the client asked for and writes it back.
The playground groups connections into apps by client id: one app is one client id, however many brokers it connects to. An app becomes a producer on its first produced record, a consumer on its first fetch or group request, and an admin on its first admin request, such as creating a topic, describing the cluster or listing groups. That is what the app list in the panel behind the status pill shows.
Ticks
The bridge is the clock. It sends the tab a tick every 1200 ms, and the tab advances the simulated cluster one step per tick, so your records move across the canvas at a pace you can follow.
- Produced records wait in a queue. Each app has a quota of 200 records a second, saved up to 3000, and a tick admits at most 1000 records of all apps together; the rest wait for later ticks, and once an app is over its quota the answer carries a throttle time that tells the client to slow down, as a Kafka quota does.
- A fetch with nothing to read waits for a record or for the client’s maximum wait, as on a broker.
- While the playground is paused, ticks still arrive but nothing advances. Requests are not answered, the bridge answers them itself with retriable errors when they time out, and the clients retry until you press Play. The playground says so while it is paused.
- The playground’s own idle pause is off while a bridge is paired, so a tab in the background keeps serving your clients.
If the tab does not answer in time, the bridge does: REQUEST_TIMED_OUT for a produce, NOT_LEADER_OR_FOLLOWER for a fetch, and the matching retriable error for the rest. See Error codes.
Explicit opt-in
The playground never talks to your computer on its own:
- Each page load starts with the bridge off. Nothing stores the on state, so a reload, a new tab or a shared link comes up disconnected.
- The Connect button is the only thing that opens the WebSocket. No URL, scenario, embed or action-log entry can, and the playground sends no probe before the click.
- A link with
#bridge=<code>only fills in the pairing code; you still press Connect. - The bridge is offered in free play of the full playground only. Switching to a scripted scenario disconnects, and the embedded playground never shows it.
- While paired, the status pill in the top bar says so. It opens the panel with the apps, their produce rates and Disconnect.
Security covers the bridge’s side of the same question.