09 / 25 · Service boundaries
API gateway
An API gateway is an entry layer that applies shared API policies and routes requests to services. Authentication, quotas and request validation may live there, but business authorization still belongs near the protected data.
What you will practise
- Separate authentication from authorization
- trace routing
- bound fan-out
Before you start: Authentication, service and record ownership.
About 4 minutes · offline-generated English female narration · captions included. Diagrams are conceptual; timings are illustrative.
Download MP4CaptionsListen without the video
Download audioChapters and full transcript
Let us understand api gateway. A school reception desk checks visitor identity and sends visitors to the right office. Passing reception does not mean a visitor can open every cupboard. Services still decide which records or actions that person is permitted to access. An API gateway is an entry layer that applies shared API policies and routes requests to services. Authentication, quotas and request validation may live there, but business authorization still belongs near the protected data.
Follow the normal path. The client calls a public API address. The gateway provides a shared routing boundary instead of requiring clients to know every internal service location. Validate the request and supported identity credentials with maintained security libraries. Reject oversized or invalid traffic before forwarding expensive work. SeatSpot exposes event, order and payment services through one public API. Shared routing and coarse policies can be managed consistently, while each service owns its business rules.
Now change one condition. Event requests go to the event service; order requests go to the order service. API versions and paths should have deliberate routing rules. A common misunderstanding is this: The gateway replaces all service authorization. Each service must protect its business actions and resources. Think about this. A valid user changes /orders/17 to /orders/18. Which boundary must still verify ownership? Pause the video and make your prediction. The order service or data-access boundary must authorize that record. Passing gateway authentication is insufficient.
Let us reason with a concrete example. A mobile screen calls events and orders through one gateway. Its latency includes gateway work plus downstream waits. Two parallel calls take approximately the slower path plus overhead; two sequential calls add their delays. Real dependency behavior and timeouts determine the result. Keep routing/coarse policy central but preserve domain authorization and tracing in services. Test a gateway outage and a single unhealthy downstream service. These figures are teaching examples, not production guarantees.
Turn the idea into a design decision. The order service checks ownership and allowed actions using verified identity. Passing gateway authentication does not grant access to another visitor order. If one API request fans out, set deadlines and partial-failure behavior. A slow optional service should not hold every gateway worker indefinitely. When you try the practice task, look for this result. A verified identity does not grant access to every record.
Check your understanding. Trace requests through the boundary and test gateway capacity and redundancy. Centralizing policy is useful, but it also creates an important operational dependency. Here is a challenge. A signed-in user changes an order ID in the URL. Which component must stop cross-user access? Pause before the answer. The order service must perform resource-level authorization using verified identity. Gateway checks are useful but cannot replace ownership enforcement. For an interview, explain token checks, quotas, deadlines and resource ownership. Say what you would measure, not only which tool you would buy.
Start with an everyday picture
A school reception desk checks visitor identity and sends visitors to the right office. Passing reception does not mean a visitor can open every cupboard. Services still decide which records or actions that person is permitted to access.
Why SeatSpot needs this
SeatSpot exposes event, order and payment services through one public API. Shared routing and coarse policies can be managed consistently, while each service owns its business rules.
Trace one step at a time
Move through the diagram at your pace. Teal paths are active; unavailable components are labelled.
Enter one API boundary
The client calls a public API address. The gateway provides a shared routing boundary instead of requiring clients to know every internal service location.
Read all six mechanism steps
Enter one API boundary
The client calls a public API address. The gateway provides a shared routing boundary instead of requiring clients to know every internal service location.
Apply coarse policy
Validate the request and supported identity credentials with maintained security libraries. Reject oversized or invalid traffic before forwarding expensive work.
Route by responsibility
Event requests go to the event service; order requests go to the order service. API versions and paths should have deliberate routing rules.
Authorize the record
The order service checks ownership and allowed actions using verified identity. Passing gateway authentication does not grant access to another visitor order.
Bound aggregation
If one API request fans out, set deadlines and partial-failure behavior. A slow optional service should not hold every gateway worker indefinitely.
Operate the entry tier
Trace requests through the boundary and test gateway capacity and redundancy. Centralizing policy is useful, but it also creates an important operational dependency.
Pause and make a prediction
A valid user changes /orders/17 to /orders/18. Which boundary must still verify ownership?
Correct a common misunderstanding
Claim to question: The gateway replaces all service authorization.
Better explanation: Each service must protect its business actions and resources.
Trace a protected order request
- Draw the client, gateway and order owner.
- Mark token validation at the gateway.
- Mark record ownership at the service and test another user’s order ID.
Check what you can explain
This is your self-check, not an automated grade. Try again without the diagram tomorrow.
0 of 3 goals checked. Choose one remaining idea to practise next.
Teach it back
Without looking, explain what this component changes, what it does not solve and what happens if it fails. Use the animation to check your explanation, then switch to Engineering.
Engineering model and trade-offs
An API gateway may terminate TLS, validate tokens, apply request limits and route by API version/path. A reverse proxy can overlap with these capabilities; these are roles, not necessarily separate products.
Verify token issuer, audience, expiry and signature using a maintained implementation. Do not trust user-supplied identity headers. The order service must still verify that this user owns the requested order.
Protect the gateway itself with capacity, redundancy and observability. Aggregating many downstream calls can create latency and failure coupling; define deadlines and keep the entry layer from becoming a large business-logic monolith.
Work through an example
A mobile screen calls events and orders through one gateway.
Reason with the numbers
Its latency includes gateway work plus downstream waits. Two parallel calls take approximately the slower path plus overhead; two sequential calls add their delays. Real dependency behavior and timeouts determine the result.
Make a decision
Keep routing/coarse policy central but preserve domain authorization and tracing in services. Test a gateway outage and a single unhealthy downstream service.
Implementation sketch
GET /api/events/:id -> event service
GET /api/orders/:id -> order service
Gateway: validate token, request size, coarse quota
Order service: verify ownership for this orderArchitecture sketch only. Paths and policy wording are illustrative, not a deployed gateway or complete authentication implementation.
Where this is used
- A managed public boundary for several APIs.
- Consistent token validation, coarse quotas and version routing.
Common mistakes
- Assuming token validation proves ownership of every resource.
- Forwarding client-supplied identity headers as trusted identity.
- Creating one unbounded aggregation request.
Practise a reasoned answer
Answer aloud or write notes before opening the reference. These prompts teach reasoning and trade-offs; they are not claimed questions from a particular company.
API gateway versus reverse proxy?
Choose a practice depth
- Foundation
- Describe routing through one API boundary.
- Practical
- Explain token checks, quotas, deadlines and resource ownership.
- Advanced
- Defend aggregation budgets, redundancy, key rotation and policy bypass risks.
Self-check rubric
- State the required user outcome and the relevant invariant.
- Explain the normal path and one failure path.
- Name a cost or consistency/latency trade-off.
- Say what you would measure or test before trusting it.
For deeper practice, connect this topic to the previous lesson and identify a shared bottleneck. A longer answer is not automatically a better answer.
Try it before viewing the solution
A signed-in user changes an order ID in the URL. Which component must stop cross-user access?
Check one key idea
Your explanation and interview notes
Saved only in this browser when storage is available. Export a backup from the course page before clearing browser data or moving devices.
Loading your local notes…
Official references and next reading
The explanation, fictional examples and animations are original teaching material. Vendor behavior depends on the specific product/version; use its documentation before deploying.