Requests networking and APIsFollow one request. Understand every boundary.
Requests networking and APIs. Learn the concepts, explore a model and defend your design.
02SYSTEM DESIGN
DEFINITION
A request is a message asking a service for information or an action. Networking carries it between machines. An API is the contract defining accepted inputs, actions, outputs and errors. A good API makes ownership, limits and failure behavior clear rather than assuming that a valid URL or a successful connection implies permission.
Finding a service is different from asking it for data
STEP 11. DNS lookupFind the service address
STEP 22. TLS connectionProtect communication
STEP 33. HTTP requestAsk the application
Connections can be reused. DNS is a lookup step, not a database hop for every request.
CONCEPT 1
How your browser finds a server
DNS is a name lookup
Typing a website name is like looking up a business in a contact list. The Domain Name System, or DNS, helps turn a name into records used to locate a service. The answer may be cached for a while, so changing a server address does not instantly change every user's view. DNS is not the server that stores your orders; it helps the client find where to send requests.
Connections and TLS
A client establishes a communication connection using an appropriate transport. TLS provides encryption in transit and helps the client verify the server's identity. An analogy is using a sealed conversation with someone whose identity you checked. That analogy has a limit: encryption cannot stop an authorized server from making a programming mistake or deciding the wrong user may see a receipt.
The request still has more work to do
A reverse proxy can accept the request and forward it to the application. The application may call a database or another service. The response then travels back. Slow DNS, connection setup, server computation, storage waits and large downloads can all contribute to a slow user experience. Measuring only the application function misses part of the journey.
CONCEPT 2
HTTP is the language of the exchange
Methods express intent
HTTP defines request and response behavior. GET asks for a representation; POST commonly asks a resource to process submitted data. PUT describes creating or replacing a resource at the chosen address. DELETE asks to remove a resource association. These names do not implement correctness by themselves. The application must make its actual behavior match the contract it presents.
Status codes communicate a result
A 200 response usually means the request succeeded. A 201 can identify creation. A 400 indicates a problem with the request, 401 concerns missing or invalid authentication, 403 indicates refusal and 404 indicates the resource was not found. A 429 is useful for rate limiting. A 500-class result indicates a server-side failure. Exact error details must avoid leaking private information.
Version and transport are separate from your business rules
HTTP/1.1, HTTP/2 and HTTP/3 differ in how communication is carried and organized. Newer transport behavior can help some workloads, but does not repair a slow database query or broken permission check. HTTP is described as stateless because each request has its own meaning; a web application can still maintain account and session state outside that protocol exchange.
Read an HTTP exchange
CONCEPTRequestMethod + path + headers + body
CONCEPTProcessingValidate input and permission
CONCEPTResponseStatus + headers + body
A status code summarizes the result; the API contract explains what the result means.
CONCEPT 3
An API is a contract between programs
Specify inputs and outputs
An application programming interface, or API, says how one program can use another. For POST /orders, describe accepted item identifiers, quantity limits, response fields and errors. The server determines the authenticated customer and trusted price. It must not accept a client-supplied owner or total as proof. TypeScript types help developers, while server validation protects the running system.
Keep list responses bounded
Suppose GET /my-orders returns one page of orders. A maximum page size prevents a single request from asking for everything. Offset pagination skips a number of rows; it is simple for small lists, but concurrent inserts can shift positions. Cursor pagination continues after an ordering position. Use a stable tie-breaker, such as creation time plus an order ID, so two orders with the same timestamp can still be ordered.
What a cursor does not do
A cursor is a bookmark, not an access pass. Even if it contains an order ID or is signed, the server must restrict the results to records the caller may read. Changing a contract needs care because old clients may keep running. Adding an optional response field is usually easier to manage than silently changing what an existing field means.
Identity is not the same as permission
STEP 1AuthenticateWho is requesting?
STEP 2AuthorizeMay they read order 52?
STEP 3ReturnOnly permitted fields
Knowing the user identity is the start of the access check, not its conclusion.
CONCEPT 4
Choose how the client receives updates
Request-based communication
With polling, the client repeatedly asks whether an order is ready. It is easy to understand, but frequent checks create repeated work. Long polling lets a request wait for an update or a timeout before the client asks again. Server-Sent Events can stream server-to-client updates over HTTP. These choices fit different update frequency, connection and deployment requirements.
Two-way and service communication
WebSockets support a continuing two-way connection, useful for chat or interactive applications. A connection still needs authentication, limits and reconnection behavior. REST-style APIs organize operations around resources. GraphQL lets clients request a structured set of fields, while gRPC uses defined service contracts and commonly generated clients. None is automatically best for every application.
A canteen example
If order status changes only twice in ten minutes, polling every 15 seconds may be an acceptable first version. If thousands of users need near-immediate delivery updates, a streaming connection could reduce pointless checks. Decide using update frequency, user expectations, operating cost and mobile network behavior. Reconnection should ask for missed state; an open connection alone does not make messages durable.
Three ways to deliver updates
CONCEPTPollingClient asks repeatedly
CONCEPTSSEServer sends one-way events
CONCEPTWebSocketBoth sides exchange messages
Choose using update frequency, acceptable delay and recovery behavior, not novelty.
Key learning points
DNS locates a service; it is not the application database.
TLS protects communication in transit but does not decide business authorization.
Trace connection setup, proxy, application, storage and response transfer.
Validate inputs at the server and derive ownership from authenticated identity.
Bound list sizes and give pagination a stable ordering.
Compare the important ideas
Requests networking and APIs: concepts and trade-offs
Choice
How it works
Good fit
Main caution
Polling
Client asks repeatedly
Infrequent status updates
Repeated checks add load
Server-Sent Events
Server streams updates to a client
One-way live updates
Reconnect and missed-state policy still needed
WebSockets
Continuing two-way connection
Interactive chat or collaboration
Connection state is not durable message storage
Cursor pagination
Continue after an ordered position
Large changing lists
Cursor does not authorize access
WORKED EXAMPLE
Trace an order-status request
Riya asks for order 52. The browser uses DNS as needed, establishes or reuses a secure connection and sends a request. The application verifies identity and checks that Riya may read order 52 before returning the current status. If the status changes only twice in ten minutes, polling every 15 seconds may be a reasonable first version. The interval is a product decision, not a universal recommendation.
Further reading
Original teaching explanations by Buildfest Learn. Check these primary references for the underlying concepts and implementation details.
Change the viewer count and polling interval. Compare polling with streaming for a status that changes twice in ten minutes.
110,000 viewers
2Repeated polls
31,000 polls/s
1,000 average polling requests/s
For infrequent order-status changes, polling may be sufficient. SSE can support one-way updates; two-way interaction can justify WebSockets. All choices need reconnect and authorization policies.
Chapter review: two questions
Attempt both questions before opening the model answers.
Question 1
An order-status page has 10,000 active viewers and polls every 10 seconds. Estimate the average polling request rate and give one reason to change the update method.
Reveal model answer
Assuming uniformly spaced polls, 10,000 / 10 gives about 1,000 requests per second. Synchronized polling can be burstier. A streaming method may help when updates are frequent or low-delay delivery is required, while a longer polling interval may be enough for infrequent updates.
Question 2
Design GET /my-orders with a page size of 50. Explain the ordering, cursor and ownership checks, including what happens if a cursor refers to another student.
Reveal model answer
Order by a stable pair such as created_at and id, restrict all records to the authenticated student and use the cursor only as a traversal position. A signed or opaque cursor is not permission. Reject invalid cursors or return only permitted results under a documented policy; never expose another student's records.
Answers stay in this tab. Download before leaving. This practice is not graded or saved to your account.