Visualizations
132 / 500

132 · Simulation

Congestion Control

TCP flows share one bottleneck as cars on a night on-ramp. Watch the sawtooth emerge.

Every packet is a car: it leaves its sender's garage, waits in the router's buffer at a ramp meter, crosses the bottleneck at 120 packets per second, and an ACK rides back along the top road. Underneath is a packet-level discrete-event simulation where each sender runs its own controller on a congestion window: Reno adds one packet per round trip and halves on loss, CUBIC chases a cubic curve around its last maximum, and Vegas backs off when its round trips stretch before anything is dropped. Nobody coordinates, yet the windows saw up and down around what the pipe plus the buffer can hold, which the gauge above the road shows directly. Make the buffer huge and the queue snakes through the yard while delay balloons (bufferbloat); switch on CoDel and the delay collapses.

Try it. Add Reno, CUBIC or Vegas flows (1, 2, 3), click a garage (or press X) to remove a flow, click any car to drop that packet, change the buffer size ([ and ]), toggle drop-tail or CoDel (C), cycle the slow-motion speed (S) and pause with Space. R restarts. Left alone, it tours bufferbloat, CoDel and flows joining and leaving.

  • Discrete-event packet simulation
  • AIMD, CUBIC and Vegas congestion control
  • CoDel active queue management
  • Jain's fairness index

View the source · one module, plus a small shared runtime for sizing, the animation loop and input

Build your own

Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.

Build a visual TCP congestion control simulator with JavaScript and the HTML canvas element. Put everything in a single index.html file with no libraries or build step, so I can open it directly in a browser.

Start simple:
- Simulate three senders sharing one bottleneck link that forwards 100 packets per second, with a router buffer of 16 packets in front of it. Use an event queue sorted by time: a packet reaching the router, the link finishing a packet, a packet reaching the receiver, an ACK getting back to its sender.
- Each sender keeps a congestion window (cwnd) and keeps that many packets in flight. Start with Reno: on each ACK add 1/cwnd (one packet per round trip); when a packet is dropped because the buffer is full, halve cwnd, but at most once per round trip.
- Draw it as a road: packets are small colored cars that drive from each sender to the router, queue up bumper to bumper, cross the link one at a time, and come back as little dots for the ACKs.
- Under the road, plot every sender's cwnd over the last 15 seconds. The sawtooth should appear on its own.

Once that works, make it beautiful and teach something:
- Run it slowed down (one eighth speed) so every car is visible, and give it a night palette with headlights.
- Add CUBIC (cwnd follows C(t - K)^3 + Wmax after each loss) and Vegas (back off when RTT rises above the minimum) so different controllers compete.
- Plot queueing delay, and show each sender's throughput and Jain's fairness index.
- Let me change the buffer size so a big buffer causes bufferbloat, and click a car to drop it.

Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as CoDel or RED active queue management, BBR's bandwidth and RTT probing, or senders with very different round-trip times.
PreviousFoamSoap foam coarsens under von Neumann's exact law, with live T1 swaps and vanishing cells. NextEvolving WalkersCreatures learn to walk by evolution, one generation at a time.

Related visualizations

  • Race Condition RailwaySimulation Threads as trains, locks as single-line tokens: deadlock and data races you can crash.
  • Quantum BilliardsPhysics A quantum wave packet bounces around chaotic billiards and leaves scars.
  • Water EconomySimulation A glass-and-brass hydraulic computer where water is money and valves are policy.
  • Max Flow WaterworksAlgorithms Water fills a hand-drawn pipe network until the minimum cut lights up in red.
  • Crowd Flow FieldsSimulation Two armies of 3,600 units pour across a river map, steered by one Dijkstra each.
  • Raft ConsensusAlgorithms Five servers on a whiteboard elect a leader and replicate a log. Now break them.
  • RRT* ParkingAlgorithms A self-driving car grows a tree of curved manoeuvres, then reverses into its spot.
  • PCB AnnealerAlgorithms Simulated annealing places chips on a circuit board, then a maze router lays copper.
  • Sorting NetworkAlgorithms A sorting network as a wooden marble run: brass gates swap marbles into order.

Use ← and → to move between demos. While the canvas has focus, keys go to the demo instead.

← More from Emergent Mind Labs