Part 07 / Topic 2 of 7
Saathi Ops Console: Suspense boundaries around slow server components
A delivery-partner operations console for a Swiggy-style dispatch team, built at harness/app/ops/page.tsx. This course never calls a real upstream service (see TOOLING.md's conventions) — every "slow" read below is a local setTimeout-based delay, in harness/app/ops/lib/delay.ts:
export function wait(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
// 1200ms — deliberately the slowest read on the dashboard.
export async function getDelayedOrders(): Promise<DelayedOrder[]> {
await wait(1200);
return delayedOrders;
}
// 500ms — faster, so sibling boundaries provably resolve in a different order.
export async function getNearbyPartnerCount(city: string): Promise<number> {
await wait(500);
return nearbyPartnerCounts[city] ?? 0;
}
// Synchronous, no await at all.
export function getTodaysSummary() {
return { deliveries: 1842, avgMinutes: 23 };
}
The page wraps each slow read in its own <Suspense> boundary, as two sibling boundaries:
export default function OpsConsolePage() {
const summary = getTodaysSummary(); // no await — part of the static shell
return (
<main style={{ fontFamily: "system-ui", padding: "2rem", maxWidth: 560 }}>
<h1>Saathi Ops Console</h1>
<p>Deliveries today: {summary.deliveries} · Avg delivery time: {summary.avgMinutes} min</p>
<h2>Live delayed orders</h2>
<Suspense fallback={<p id="orders-fallback">Checking delayed orders…</p>}>
<LiveDelayedOrders />
</Suspense>
<h2>Partners nearby</h2>
<Suspense fallback={<p id="partners-fallback">Counting partners online…</p>}>
<NearbyPartners />
</Suspense>
</main>
);
}
LiveDelayedOrders and NearbyPartners are each a separate async function component that awaits its own data — not two awaits inside one function. That separation is what lets the two boundaries resolve independently.
Watching the real response, not guessing at it. curl buffers a response with no newlines in it (section 6 proves this), so this course uses a small Node script that reads the response body as a stream and timestamps each chunk — examples/05-stream-observer.mjs. Run for real against this course's harness (next start, port varies):
$ node examples/05-stream-observer.mjs http://localhost:PORT/ops
chunk 1 at +41ms (1829 bytes)
chunk 2 at +58ms (6078 bytes)
chunk 3 at +58ms (5224 bytes)
chunk 4 at +546ms (158 bytes)
chunk 5 at +547ms (1041 bytes)
chunk 6 at +1245ms (424 bytes)
chunk 7 at +1245ms (492 bytes)
chunk 8 at +1246ms (14 bytes)
---summary---
status: 200
total chunks: 8
first chunk has h1: true
id="orders-fallback" arrived at: +41ms
id="delayed-orders" arrived at: +1245ms
id="nearby-partners" arrived at: +547ms
(The exact millisecond counts vary run to run — (varies). What doesn't vary: the <h1> and both fallbacks are in the very first chunk; NearbyPartners (500ms simulated delay) swaps in around the ~550ms mark; LiveDelayedOrders (1200ms simulated delay) swaps in roughly 700ms later, around ~1245ms — in the order the data actually finished, not the order the JSX was written in.) That is "they don't block each other," measured rather than quoted.
Full files: examples/01-delay-simulation-lib.ts, examples/02-ops-console-page.tsx.
Done here? The practice set for Part 7 — including the solutions — is on the part page.