WEEK 0

What Is a Real-Time Intelligent System?

Before any Python: a real-time system is not a fast system, it is a system with a deadline — and an answer that arrives after the deadline is not a slow answer, it is a wrong answer. Everything else in this course is one loop, built ten weeks deep, with intelligence pushed inside that deadline.

No code on this page Read before week 1 A late answer is a wrong answer
Part 1

1What is it? A deadline, a decision, and a loop

Two words, and both of them are usually misread. Real-time gets read as “fast”; intelligent gets read as “machine learning”. Neither is right, and the cost of the misreading is a system that is quick on a laptop and useless in production.

“Real-time” is a deadline, not a speed

A system is real-time when its correctness depends on when the answer arrives, not only on what the answer is. The deadline is set by the world — by how fast the price moves, how fast the car travels, how fast the furnace heats — and no amount of engineering negotiates it down. Your only choice is whether you meet it.

So “is it fast enough?” is the wrong question. The right one is: what is the deadline, how often do we miss it, and what happens on the miss? A system that answers in 2 ms with a deadline of 1 ms fails. A system that answers in 4 hours with a deadline of a day is real-time. Speed is relative to a clock that somebody else owns.

The three classes below are engineering choices, and you have to pick one per decision, not per system. Most real systems are a hard core wrapped in firm middle layers wrapped in a soft shell — and confusing which layer you are in is how a dashboard ends up blocking a brake command.

hard

A miss is a failure

Steering, braking, an airbag, a motor commutation loop, a pacemaker. The deadline is part of the safety case, so the design is driven by the worst case, never the typical one.

firm

A late answer is worthless

A quote, a bid, a video frame, a card authorisation. Nothing breaks, but the late answer has zero value and is thrown away — which is why lateness shows up as lost revenue rather than as an error log.

soft

A late answer is degraded but still useful

A dashboard, a nightly risk report, a recommendation. Value decays with lateness instead of falling off a cliff. Almost all “real-time analytics” products are soft real-time, and that is fine — as long as nobody puts one in the hot path of something firm.

Four numbers people call “speed”

namewhat it actually measures
latencyhow old your input is when you act on it
throughputhow many events per second you can absorb
jitterhow much latency varies cycle to cycle
deadlinethe instant after which the answer is worthless
Latency and throughput are not the same axis. Batching 500 events raises throughput and raises latency; it is the standard way to make a benchmark look good and a deadline get missed. You can always buy throughput with more machines. You cannot buy latency that way — a bigger cluster does not make one decision arrive earlier.

Why the mean is a lie

Report a mean latency and you have hidden exactly the events that matter. If one request in a hundred takes forty times the median, the mean barely moves — and one per cent of your decisions are wrong. At a thousand decisions a second that is ten wrong decisions every second, all invisible in the average.

So the metrics in this course are p50, p99, p99.9 and a deadline-miss count. The tail is the system. Part 2 makes that concrete with two systems that have the same mean and completely different fates.

what you report
mean
what breaks you
p99.9

“Intelligent” means a decision computed from live data

Not a model. A decision. The system observes the world as it is right now, chooses an action, and takes it — with consequences. The intelligence can be four lines of arithmetic or a neural network; what makes it interesting is that it sits inside the loop, under the deadline, where being clever costs milliseconds and milliseconds cost correctness. An offline model that is 4% more accurate and 300 ms slower can be strictly worse than the rule it replaced. That trade is the subject of this whole course, and Part 2 lets you make it with a slider.

Where the intelligence is not

  • In the training script. That runs offline, with no deadline and all the data.
  • In the dashboard. That reports the decision; it does not make it.
  • In the size of the model. A 7-billion-parameter model that answers after the deadline contributes exactly nothing.

Where it is

  • In the one function that turns current state into an action, and returns before the clock runs out.
  • In the fallback that fires when that function is late — because the fallback makes just as many real decisions as the model does.
  • In the monitor that notices the world has drifted away from the assumptions the decision was built on.

Widget 1 · the anatomy of the loop, against a deadline

Every system on this page is these six stages. Click one to see what it is, what it costs, and how it fails. The ruler underneath stacks the six stage budgets — at the median and at the 99th percentile — against the deadline you set. Watch the p99 bar, not the p50 bar: a loop can sit comfortably inside its budget on a typical cycle and blow through it on one cycle in a hundred.

the stage you selected the other five stages the deadline
loop p50
—
loop p99
—
headroom at p99
—
verdict
—
stage week

—

—

budget— fails as—
—
Part 2

2How does it work? Two experiments you can run right here

The first experiment separates “fast” from “real-time” using two systems with an identical mean latency. The second buys accuracy with latency and watches it stop being worth the money. Together they are the two decisions you will make every week for the next ten weeks.

Set them up honestly. System A is the one everybody builds: a fast path with an occasional stall — a garbage collection, a lock, a cache miss, a log write that touched the disk, a retry, a Python allocation at the wrong moment. System B is boring: slower on a typical event, but bounded. Both report the same average latency to management. Only one of them is real-time.

Widget 2 · “fast” versus “real-time”, at the same mean

Drag the tail weight. As more of A's events fall into the stall, A's fast path gets faster to keep the mean pinned at the same value — the histogram body slides left while the tail stays where it is. A looks better on every average you can compute, and misses more deadlines on every drag. Then drag the deadline and watch which system you would rather own.

system A · fast on average system B · bounded past the deadline — a wrong answer
system A · fast on average
mean— p50— p99— p99.9— missed—
system B · bounded
mean— p50— p99— p99.9— missed—
wrong answers · A
—
wrong answers · B
—
—
Run it in this order. Leave the deadline at 40 ms and push the tail weight from 0.5% to 9%: A's mean never moves, A's p50 improves, and A's miss count climbs past B's by an order of magnitude. Now raise the reported mean to 30 ms — B starts missing too, because a bounded system with a bound above the deadline is just a reliably wrong system. Both facts are invisible in a mean, and both are obvious in a p99.

The intelligence ladder — and the rung where it stops paying

There are four ways to compute a decision from live data, and they form a ladder: each rung is more accurate, more expensive, and fails in a nastier way. Nothing forces you to the top. What decides the rung is the deadline — and the fact that a decision which arrives late does not merely score zero, it usually scores negative, because something downstream already acted on the stale answer.

Widget 3 · buy accuracy with latency, until it stops being worth it

Each rung gets a thousand decision opportunities. A decision that lands inside the deadline scores its edge; one that lands late either falls back to the cheap rule or acts on stale state, depending on the switch. The capacity slider makes every rung bigger: more accurate, and slower. Find the deadline at which the learned model beats the rule — and the deadline at which it stops.

rung week

—

—

decision— latency— accuracy— fails as—
value earned on time value lost to late decisions the ceiling — what it would earn if it never missed
—
The shape to remember. Every curve rises, peaks, and falls. It rises because accuracy is worth something; it peaks where the rung's p99 approaches the deadline; it falls because past that point you are buying accuracy you cannot deliver on time. The agent rung is the extreme case: it is the most accurate thing on the ladder and, at a 20 ms deadline, worth less than four lines of arithmetic. Set the switch to act on stale state and it goes negative.
Part 3

3Why does it matter? The same loop, six industries

The reason this is one course and not six is that the loop does not change. Swap the sensor, swap the actuator, change the deadline by four orders of magnitude, and the engineering stays recognisably the same: bound the tail, keep the decision inside the budget, degrade on purpose, measure everything, be able to replay it. Learn it once in a market, and the fraud detector and the car are re-parameterisations.

Accuracy versus latency

Every point of accuracy is bought with time: more features, a longer window, a bigger model, another confirmation. Past the deadline the purchase is worthless. Widget 3 is this trade.

Freshness versus cost

Fresher state means polling harder, holding more in memory, and duplicating work per node. You can always be fresher; you cannot always afford it. Ask what a millisecond of staleness actually costs before you buy it.

Safety versus autonomy

The safe move is to do nothing when unsure — but a system that abstains constantly is not doing its job. Every real system encodes where that line is, usually as a threshold nobody wrote down. Write it down.

Widget 4 · the domain explorer

Pick an industry. The diagram is the same six stages every time; only the labels, the numbers and the consequences change. The deadlines are real order-of-magnitude figures — read them next to each other, because the spread from a motor loop to a fraud rule is five orders of magnitude and the code looks almost identical.

deadline
—
event rate
—
class
—

—

—

sensor— state— decision— actuator— measure—
what “wrong” costs

—

too late— too eager—
—
One more, for scale. A mobile network scheduler decides which handset transmits in the next half-millisecond slot, thousands of times a second, per cell — and the low-latency service class it supports targets about 1 ms end to end. Same loop: sense the channel, decide the allocation, act on the air interface, measure the result. The deadline is just smaller than anything else on this page.

One concrete example, end to end

You run a market-making desk in the class arena. Your loop: read the top of the order book, decide a bid and an ask around your estimate of fair value, send both, and watch what fills. Your deadline is set by how long your quote survives before the fair value has moved underneath it — call it 50 ms in this arena.

Now put intelligence in it: a model that predicts the next move and skews your quotes accordingly. Offline it is clearly better. Online it takes 70 ms at p99. On the one-cycle-in-a-hundred where it is late, your old quote is still resting on the book at a price the world has left behind — and the only counterparty who wants it is the one who already knows. You do not lose the spread on that trade; you pay someone else's.

That is the whole discipline in one paragraph. The model did not fail. The model was late, which in a real-time system is the same thing as being wrong, except that it does not show up as an error — it shows up as a slow bleed in the P&L that no unit test will ever catch. Weeks 3 and 4 have you build exactly this and measure exactly that.

Three fixes, and what each one costs

pull the quoteCheapest and safest: when the model is late, cancel rather than rest. You stop bleeding and you stop earning. This is graceful degradation, and it needs a stated rule — not a hope. cheaper modelDrop a rung on the ladder. You give up accuracy you were never delivering on time anyway. Usually the right answer, and always the unpopular one. cut the tailFind the p99 and remove it: the allocation, the lock, the log write, the unbounded await. Hardest, most valuable, and the only fix that does not cost you anything in accuracy.
What you never do is raise the deadline. It is not yours.
Part 4

4Five ways this goes wrong before any code is written

These are conceptual failures, not bugs. Every one of them survives code review, passes its tests, and shows up in production as something nobody can explain. Open them.

Optimising the average, then being destroyed by the tail

The benchmark says 4 ms. Production says 4 ms. The deadline is 20 ms. And once every few hundred events something stalls for 300 ms — the garbage collector, a lock, a log flush that hit the disk, a DNS lookup, a socket buffer filling. Averages absorb all of it.

Worse, the usual optimisations make it worse: batching, caching, adding a queue to “smooth the load”. Each one improves the mean and lengthens the tail. A queue in front of a deadline is a machine for converting a capacity problem into a correctness problem.

Fix: state the deadline first, then measure p99 and p99.9 and a miss count, and treat the worst observed case as the number that describes your system. If a change improves the mean and worsens p99, it is a regression.

Confusing throughput with real-time

“We process two million events a second” answers a different question from “we decide within 10 ms”. High-throughput architectures win by batching and buffering, which is exactly the wrong instinct under a deadline: the system is busy and healthy and every individual answer is late.

The tell is a design that scales by adding partitions and a design goal expressed in events per second. Both are fine — for the ingest stage. Neither says anything about the decide stage, where the deadline lives.

Fix: separate the two budgets explicitly. Ingest is a throughput problem and may batch; decide is a latency problem and may not. Put the boundary between them in your diagram, and put a bounded queue with a drop policy on it — not an unbounded one.

Treating stale data as current data

Every value your system holds has an age, and almost no codebase stores it. So a price from 400 ms ago, a position from before the last three fills, a camera frame from two frames back and a fresh tick all arrive at the decision function looking identical — and the decision is computed on a world that does not exist.

This is the most common way an intelligent real-time system produces confident nonsense. The model is fine. The inputs disagree about what time it is.

Fix: timestamp at the source, carry the timestamp with the value, and make the decision function check the age of what it is about to use. An input older than its budget is not an input; it is a reason to degrade. “No answer, on time” beats “a good answer, computed from last week”.

Assuming a global clock, and a whole system that is up or down

Two machines never agree on the time — ordinary clock offsets are milliseconds and can be far worse — so “event X happened before event Y” is a claim you cannot make from two timestamps taken in two places. Meanwhile failure is not binary: the interesting state is the one where a peer is alive, reachable, and answering 800 ms late, or answering with stale data, or answering wrongly. Partial failure is the normal case.

Every distributed real-time system you will meet has this shape, and the reflex — retry, wait, block until the peer responds — converts one slow peer into a system-wide deadline miss.

Fix: order events with sequence numbers from a single writer rather than with wall clocks; put a timeout with a defined fallback on every remote call; and decide in advance what your system does with a peer that is late rather than dead. Week 5 makes you cut a link and live with it.

Deploying a decision with no monitor, into a world that moves

The decision rule was fitted to a world, and the world drifts: volatility regime, traffic mix, lighting, seasonality, a new product, a new attacker. Accuracy decays quietly, and because the system keeps answering on time, every dashboard stays green. Add an adversary — someone who profits from your predictable response — and the drift stops being accidental: your own behaviour becomes the thing being exploited.

The second half of this pitfall is that a system with no monitor cannot degrade, because nothing knows anything is wrong. It just keeps acting.

Fix: make the measure stage a first-class part of the loop, not an afterthought. Track the input distribution as well as the output, alarm on divergence between what you predicted and what happened, and give the system a defined safe state it can enter on its own. Week 9 makes you write that down as a one-page safety case.

Part 5

5Check yourself

Three questions, instant feedback, nothing recorded.

Q1Two systems, one deadline of 40 ms. A: mean 9 ms, p50 6 ms, p99 240 ms. B: mean 19 ms, p50 19 ms, p99 26 ms. Which one would you ship?

Q2Your decision arrives 15 ms after a 50 ms deadline, and it is correct. What is its value?

Q3In a real-time intelligent system, where does the “intelligence” actually live?

Part 6

6How this course builds one

Ten weeks, one system, four domains. Every week adds a stage to the loop you met in Part 1, or hardens one that is already there — and every week ends with a measurement rather than an opinion.

Widget 5 · which part of the loop each week adds

Click a week. The chips show which of the six stages it touches; the panel says what you build and what you measure. Use the arrow keys once a week is focused.

week arc

—

—

adds— measures—
—

Before week 1

  • Get Python 3.11 or newer working, and be able to run one script from a terminal.
  • Read Part 1 again and write down, in one sentence each, the deadline and the consequence of a miss for a system you already use every day.
  • Clone the starter repo and run its smoke test. You should see it go green before you see any lecture slides.

What you will not need

  • A GPU, a cluster, or a cloud account. Everything in the ten weeks runs on a laptop.
  • Prior trading knowledge. The market is the case study because it is the cheapest real-time system to stand up honestly, not because the course is about finance.
  • A background in control theory or machine learning. Both arrive in the loop, in that order, with the deadline already in place.
Code
Get the code
The starter repo is public. Use it as a template, clone it, make install, and run the smoke test before week 1.
Next
Start Week 1 · UML & OOP →
Turn this loop into objects and messages, and draw the picture before you write a line of it.
Prequel
Computer Architecture Arena
Where the microseconds in this page come from — caches, pipelines, branch prediction, and the machine your Python actually runs on.
← Course home Week 1 · UML & OOP for Real-Time Systems →