Course map
Stage 1: App Router Foundations
Stage 2: The Rendering Model
Stage 3: Data, Caching and Mutations
Stage 4: Full-Stack Next.js
Stage 5: Production and Specialization

Part 09 / Topic 1 of 5

Two upstreams, two modules, zero network calls

Mandi Fresh's product detail page needs two things a real app would get from two different backend systems: customer reviews, and warehouse stock. This part gives each one its own module under harness/app/mandi/lib/, with its own simulated latency — the same setTimeout-backed wait() convention Part 7's ops/lib/delay.ts already established, never a real fetch() to an outside service:

// harness/app/mandi/lib/reviews.ts
export type ReviewSummary = { productId: string; averageRating: number; reviewCount: number };

function wait(ms: number) {
  return new Promise<void>((resolve) => setTimeout(resolve, ms));
}

// 400ms — the simulated cost of the reviews service.
export async function getReviews(productId: string): Promise<ReviewSummary | null> {
  await wait(400);
  return reviewsByProduct[productId] ?? null;
}
// harness/app/mandi/lib/stock.ts (relevant part — section 4 covers the rest of this file)
// 350ms — the simulated cost of the warehouse stock-check service.
async function checkWarehouse(productId: string): Promise<StockInfo> {
  await wait(350);
  return { productId, unitsAvailable: unitsByProduct[productId] ?? 0 };
}
export const getStock = checkWarehouse;

Reviews is deliberately the slower of the two (400ms vs 350ms) — not an accident, section 2 needs the two numbers to be different and known, so the math in its timings is checkable by hand, not just "trust the curl output."

A third module, harness/app/mandi/lib/products.ts, holds Mandi Fresh's four products as plain synchronous data (no await at all) — the same "colocated data module, no special filename, never becomes a route" convention Part 2 already established for harness/app/store/lib/products.ts.

Done here? The practice set for Part 9 — including the solutions — is on the part page.

Search the guide