CourseAI System Design: The Complete Course · Module 7: Model Layer · part 51 of 107
Part 51 · Module 7: Model Layer

Lab: The model gateway, wired to a registry

180 min read·
Module 7 · Lab · About 60 minutes · Needs: lessons 1 to 4 of this module, and the Module 6 lab (or nothing: Step 1 rebuilds Modules 1 to 6)

What you are building

One door for every model call What this lab builds Active flow 1 Processing step number Optional or fallback Features Ask, Cases Digest Gateway Gateway.complete router, cascade fallback chain by residency Providers Groq retention off degraded mode 1 2 3 Policy residency.py decides ALLOWED model_registry.py pins, prices, dates Also written requestpath.py ADR-004 design step 6 test_gateway.py
The lab's piece: every feature calls Lesson 2's gateway (blue); the chain goes to Groq (grey, hosted) or degraded mode (dashed pink); the registry and residency.py (teal) decide what it may call. Numbers give the order.

Funmi wants every model call to go through one door that knows which models Northdesk has pinned, what they cost, when they retire and where each tenant's data may go. This lab puts the four lessons' files into the repository unchanged and adds northdesk/model_registry.py, the gateway wired to it, northdesk/requestpath.py (the 22 September replay and the request path figure) and tests/test_gateway.py. ADR-004 records the decision.

One rule changes. Lesson 2's chain let US tenants fall back to the Gemini Developer API, which Module 2's residency.py fails for every tenant, US included. The registry allows Groq (retention off) or degraded mode, nothing else; Step 4 measures the first design's mistake.

One cell calls your provider; every number quoted comes from a scripted stand-in or no model. Open a new Colab notebook, module-07-lab.ipynb, and run each cell in order.

The rest of this course is yours to keep

This course is bought on its own, once, and stays readable afterwards, including the parts added to it later.

Or open everything with a plan