MSD-101 · Global taxi booking design
AI inside the app, and AI-written code
⏱ 12 min 🎮 Hands-on ☁ Azure ✓ Completed
⚡ The 30-second answer
AI now appears in two places: inside the product (booking assistant, smarter ETA, demand forecasts, fraud checks, support chat) and in how the code is written. In both, the architect sets the rules: the model only proposes, the user confirms, normal APIs act, and AI-written code is reviewed against the design.
- AI features as design boxes
- Tool calling with confirmation
- Guardrails that cannot be talked around
- Review AI-written code
Try it
Play with the design before you read about it. Everything runs on this page.
Pick what the rider says:
-
🗣️ Rider says
-
🧠 Model returns a tool call
-
✋ Rider confirms
-
⚙️ Backend acts
You are implementing the rider and driver apps for a taxi booking system. Follow this design exactly.
Architecture:
- Commands (book, cancel, pay, rate) go over HTTPS to /v1 endpoints. Every POST that creates or charges MUST send an Idempotency-Key header (UUID v4) generated once per user action and reused on every retry.
- Live data uses ONE WebSocket per app (Azure Web PubSub client). Driver app sends {driverId, lat, lng, heading, ts} every 4 s on a trip, every 30 s when idle.
- Push notifications only wake the app. Never put trip state in a push payload as the source of truth.
Rules:
1. Save each command to a local outbox (SQLite) before sending. Retry with exponential backoff + jitter (1, 2, 4, 8, 16 s), max 5 tries, then show a clear error with a Retry button.
2. After every WebSocket reconnect or app resume, call GET /v1/trips/{id} and render that state. The server is the source of truth.
3. Store tokens only in Keychain (iOS) or EncryptedSharedPreferences/Keystore (Android). One token refresher; on 401 refresh once, then replay once.
4. GPS: balanced accuracy when idle, high accuracy only on an active trip. Batch up to 5 min of points when offline and send them oldest first.
5. Never compute fares or trip status on the device.
Write tests for: retry with the same Idempotency-Key, reconnect + resync, 401 refresh flow, offline GPS batching. 🐞 Spot the AI mistake: tap a card
✅ Architect’s review checklist
0 of 5 checked. Not ready to merge.
- The problemA product manager asks for “an AI that books rides by voice”. The first prototype lets the model call the payment API directly. In testing, someone types “refund me 50 dollars” and it works.
- The design ideaThe model proposes. The user confirms. Your API acts.
- In real lifeTeams that ship AI assistants safely treat the model like an untrusted client: everything it suggests goes through the same validation, rate limits and idempotency checks as a button tap.
Start with a question
A product manager asks for “an AI that books rides by voice”. The first prototype lets the model call the payment API directly. In testing, someone types “refund me 50 dollars” and it works.
An AI feature is a box in your diagram with inputs, outputs and permissions, like any other service.
Explain it like I'm 10
A helpful robot can fill in your form, but you still sign it. And the robot is only given the forms it is allowed to fill.
The technical explanation
Booking assistant. The rider’s sentence goes to a model on Microsoft Foundry with a small set of tools (book_ride, schedule_ride, cancel_ride). The model returns a structured tool call; the app shows a confirm card; only then does the normal idempotent booking API run.
Guardrails by design. The model has no tool that moves money or reads other users’ data, so prompt injection has nothing to reach. Add Azure AI Content Safety for harmful input and output.
Other AI boxes. ETA prediction (Azure Machine Learning, with Azure Maps as the fallback), demand forecasting, fraud checks on the location stream, and a support bot with retrieval over policy and the user’s own trips.
AI-written code. Give your coding tool the design rules, then review for the usual mistakes: retries without idempotency keys, fixed 1 s polling, tokens in plain storage, no reconnect and re-sync, and GPS at full accuracy all day.
| AI feature | Azure | Guardrail |
|---|---|---|
| Booking assistant | Microsoft Foundry (tool calling) | Model proposes, rider confirms |
| Smarter ETA | Azure Machine Learning + Azure Maps | Fall back to Maps ETA |
| Fraud checks | Stream analytics on Event Hubs | Human review, no auto-ban |
| Support bot | Foundry + Azure AI Search | Refunds over a limit go to a human |
Real-world scenario
Teams that ship AI assistants safely treat the model like an untrusted client: everything it suggests goes through the same validation, rate limits and idempotency checks as a button tap.
Test yourself
5 questions. Get 4 right and this lesson is marked complete.
Pass the quiz to complete this lesson.
Next: Design lab: same app, different problems →Questions people ask
Can I add an AI assistant to book rides safely?
Yes, if the model only proposes a structured booking (a tool call), the rider confirms it, and the normal booking API with its checks does the work. Never let the model move money or read other users’ data.
Does a taxi app need AI to work?
No. Booking, matching and pricing must work without any model. AI features such as a smarter ETA or demand forecasts sit on top, and each needs a non-AI fallback, for example the Azure Maps ETA when the ETA model is down.
Which Azure services run an AI booking assistant?
Microsoft Foundry hosts the model and its tool calling, and Azure AI Content Safety filters harmful input and output. The assistant only proposes a booking; the normal booking API does the work after the rider confirms.
What does AI-generated mobile code usually get wrong?
Retries without idempotency keys, fixed fast polling, tokens in plain storage, no WebSocket reconnect or re-sync, and GPS at the highest accuracy all the time.
Interview questions
How this topic comes up in system design interviews. Answer out loud first, then open the model answer.
beginner What is tool calling?
The model returns a structured request (tool name and arguments) instead of free text, and your code decides whether and how to run it.
intermediate How do you stop prompt injection in a support bot?
Give it only read tools scoped to the signed-in user, keep money-moving actions out of its tools, filter input and output with content safety, and send risky requests to a human.
advanced How would you review an AI-generated pull request for the driver app?
Check idempotency keys on commands, backoff with limits, secure token storage, reconnect plus server re-sync, GPS rules by trip state, and tests for each failure case.
Quick revision
Remember
- AI features as design boxes
- Tool calling with confirmation
- Guardrails that cannot be talked around
- Review AI-written code
- If a feature only works when the model behaves, the design is wrong. Remove the dangerous tool instead of asking the model nicely not to use it.
One line to remember
“The model proposes. The user confirms. Your API acts.”
Official documentation
- Microsoft Foundry Models (Microsoft Learn)
- Azure AI Content Safety (Microsoft Learn)