Contents Lesson 18 of 19

11 min read · professional

The real-time wall

By the end of this lesson you will have a cockpit that stops refreshing before your limit and keeps a reserve for a refresh by hand, says in words why it stopped and when it resumes, keeps every panel's data on screen labelled stale, and the five lines of PLAN.md filled in with your own measured numbers.

Three walls so far: your list could not stay fresh, your screen could not see the whole market, your backtest could not reach the regime that would test it. This one is different in kind, because it breaks a feature you built rather than limiting one you wanted.

The two numbers that meet

From the previous lesson, your cockpit costs a measured number of calls per refresh. From /user, you have a daily limit — on the free plan, documented as 20 API calls per day.

Put them together for the worked cockpit at 18 calls per refresh, or 13 on a free key with its screen refused: the free allowance buys one refresh a day, and not quite a second one.

That is the whole wall, and it is arithmetic rather than a policy. Twelve live quotes cost twelve calls because /real-time is priced per symbol, and no amount of batching changes it — Build Your First Tool's correction is what makes this number honest.

What breaks, precisely

The cockpit stales. Not blank, not broken — stale, which is worse, because it renders perfectly. This is why unit 2 insisted on labelling age and unit 3 insisted on showing the oldest timestamp. Without those, a person reads a confident, wrong screen.

The alert is mute. Unit 3 priced a real alert loop at 936 calls a day for 12 symbols at five-minute intervals. Against 20 calls, the alerting feature you designed cannot run at all — not degraded, not delayed. Off.

Those are the two sentences that make this wall real rather than rhetorical: your cockpit stales and your alert is mute.

Degrade honestly

A tool that hits its limit and says nothing is the failure. Three behaviours, and none of them is hard:

  1. Stop refreshing before the limit, not at it. Keep a reserve so a deliberate manual refresh still works; one refresh by hand is the natural size. On the free plan that means the loop never runs: the worked cockpit needs 18 for the next refresh (13 on a free key) plus as much again in reserve, and the whole day is 20. That is the wall, not a bug.
  2. Say what happened. "Refresh paused — 20 of 20 calls used today, resets at 00:00 UTC." A 402 rendered as "something went wrong" is the worst version of this moment.
  3. Keep showing the data, labelled. Every panel goes to its stale state with a real age. The person can still work; they just know what they are looking at.

This is unit 2's degrade-rather-than-disappear rule, and the wall is the reason it existed.

Write down what your tool cannot do

In PLAN.md:

Calls per refresh:        ___
Daily allowance:          ___
Refreshes it buys:        ___
Alert loop needs:         ___ calls/day
Therefore alerts:         ___

Fill it in with your own measured numbers. That last line usually reads "cannot run", and writing it is the point — an honest limitation you know about beats a feature you believe in that does not work.

What upgrading changes, precisely

Nothing in your code. The same cockpit, the same panels, the same layouts, the same alert evaluator you already wrote and tested — refreshing at the interval it was designed for, with the alert loop actually running.

And the same honesty as the previous three walls: if you open your cockpit once a day and read it, or twice on a lean layout that costs 10 calls or fewer a load, it fits, and you should not pay for anything. The wall matters when the tool becomes something you rely on, and the previous lesson's projection is what tells you when that happened. Live pricing is on the pricing page and deliberately not quoted here, because a number written into a lesson goes stale and then lies to whoever reads it next.

Try it now

Fill in the five lines with measured numbers, then set your refresh interval to what your allowance actually supports and use the cockpit for a day. That experience — a tool you built, running honestly inside a real limit — is the point of the whole exercise, and it is a different feeling from being told about it.

The prompt

Mock mode on, plan mode on, and paste:

Plan, then build, the wall. Add shouldRefresh to src/lib/budget.ts: no
automatic refresh once the calls left would not cover one more refresh
plus a reserve the size of one refresh by hand, while a refresh by hand
may spend the reserve. The wall holds back the loop, Refresh and Retry,
not the page's first load: the meter lags behind the API and a 402
costs nothing, so the API's answer decides that one. When it
says no, or a request answers 402, show "Refresh paused: <used> of
<limit> calls used today, resets at 00:00 UTC", and keep every panel's
rows on screen in its stale state with its real age. A 429 waits for
Retry-After and tries again; a 402 never retries. Write the tests first
in tests/budget.test.ts, including a fake fetcher that answers 402. Add a
Refresh button and, on a failed panel, a Retry button if the cockpit
does not have them yet; both go through the same wall. Then fill in
these five lines in PLAN.md with my layout's price per refresh and my
plan's limit from the usage route:

Calls per refresh:        ___
Daily allowance:          ___
Refreshes it buys:        ___
Alert loop needs:         ___ calls/day
Therefore alerts:         ___

The last line says what my alerts can and cannot do on my plan. No
live request.
Run npm test, typecheck, lint and check:leak, and show me the diff
first.

A good answer changes src/lib/budget.ts, its test, the container and PLAN.md, and touches no panel: stale is a state every panel already has from unit 2.

Check it yourself

  1. A test with the calls left inside the reserve: the loop does not refresh, and a refresh by hand still does.
  2. Set apiRequests equal to dailyRateLimit in fixtures/user.json and reload in mock mode: the panels draw as before, because the load itself is not held back. Now press Refresh: the paused line names the count, the limit and the reset time, and the panels keep their numbers with their ages. Put the fixture back.
  3. Nothing on screen in the paused state says "something went wrong".
  4. The five lines in PLAN.md are filled in, and the last says what your alerts can and cannot do on your plan.
Compare with ours
// src/lib/budget.ts: stop before the wall, not at it
export function shouldRefresh(a: { used: number; limit: number; perRefresh: number;
                                   reserve: number; byHand: boolean }) {
  const left = a.limit - a.used;
  return a.byHand ? left >= a.perRefresh : left >= a.perRefresh + a.reserve;
}
Calls per refresh:        13    (refreshCost on our default layout: 7 quotes, a screen at 5, SPY's history; 8 on a free key, which has no screener)
Daily allowance:          20    (usage route, free plan)
Refreshes it buys:        1     (2 on a free key, at 8)
Alert loop needs:         78 calls/day   (one rule symbol, every 5 minutes for 6.5 hours)
Therefore alerts:         cannot run; rules are checked while the page is open

Our layout is smaller than the worked cockpit, so its numbers are smaller; the conclusion is the same. Our reserve is one refresh by hand, 13, so after the page's own load the loop holds back for the rest of the day. The full state at the end of this unit, and of the course, is on the starter's branch ref/build-a-dashboard/u4.

The reference dashboard at the end of unit 4, in mock mode

Checkpoint

npm test && npm run typecheck
git status          # the files you expect, and no .env file
git add -A
git commit -m "Degrade at the wall: stop before the limit, say why, keep the data labelled"

Then answer this lesson's questions.