BM
Bashar ModallalSOFTWARE · AI · SYSTEMS
Backend Engineering

Beginner · Lesson 1 of 12

Software Architecture

Follow an HTTP Request

Trace a two-notebook purchase from DNS and TLS to a committed order, and learn what a checkout timeout can actually prove.

A paper order ticket hangs on a copper wire between a laptop and a server rack.

A shopper orders two notebooks. The checkout spinner turns for a moment, then the screen says “Connection lost.” A minute later the shop sends a confirmation for order 8142. Did the request fail? The shopper failed to receive an answer. The shop succeeded in recording the order. Those observations describe different points in the same conversation. Learning to tell them apart will save you from a surprisingly expensive debugging mistake: telling someone to click Buy again when their first purchase already exists.

Let’s follow that purchase through a small shop. We will give the browser a destination, watch an order become a database record, and come back with a response a customer can understand. Then we will remove just the final part of the journey and see which conclusions still hold. All prices, identifiers and timings below are invented for the example. You can reproduce the reasoning with paper and a pencil.

Write down what the customer actually sends

Our shop sells a notebook under product code N7. Its catalog price is AED 25.00. A signed-in customer chooses two and submits the checkout form. The page already knows the product code and quantity. It asks the browser to send a POST request to https://shop.example/orders, with a JSON body containing {"sku":"N7","quantity":2}. Imagine that the shop and API share the same origin and that the browser already has the session cookie. Payment and shipping are outside this example. The order will initially have the status “received.”

Look carefully at what is missing from the body. It supplies neither a customer number nor a total. The shop will identify the customer from the session and calculate the total using its catalog. A value displayed by a page can be stale or edited before submission. If the shop accepted a browser-supplied total, changing the quantity without refreshing the price could turn two notebooks into a one-notebook bill. Giving the server responsibility for this calculation makes the result predictable across web and mobile clients.

Find the machine that can answer

The browser breaks the URL into pieces. The scheme is HTTPS, the host is shop.example, and the path is /orders. For this first visit, assume there is no cached address or existing connection. The browser needs an address to contact. Its resolver asks for address records for the host. A recursive DNS resolver may follow referrals to the authoritative service and keep answers for later queries. For our drawing, write the documentation address 192.0.2.20 beside the shop name. The resolver returns that address. Nobody has received a shopping cart yet.

Try changing only the path on your paper to /returns. The host stays the same, so resolving the name will not tell you which team handles returns or whether the route even exists. This distinction matters when investigating an outage. If a lookup fails before a connection can be attempted, editing the order handler will achieve nothing. Conversely, receiving an HTTP response for an unknown path is evidence that some HTTP-speaking component answered. It tells you little about whether today’s authoritative DNS server was consulted. A cached answer may have sufficed. DNS concepts and resolver behavior, RFC 1034

Establish a protected conversation

For this example the browser uses HTTP/1.1 over TCP. It connects to the resolved address on port 443 and negotiates TLS with the shop’s front door, a reverse proxy. The browser checks that the server certificate is acceptable for the hostname and that the handshake succeeds. The two sides establish keys to protect the traffic between them. An address tells the client where to attempt a connection. The certificate check helps establish which service is answering. Pointing DNS at the right machine does not compensate for an expired or incorrectly named certificate.

The reverse proxy is the endpoint of this particular TLS connection. It can read the request in order to forward it. What protects the next connection to the application depends on the shop’s deployment. Likewise, the browser’s successful connection says nothing about whether the person is signed in or allowed to buy anything. Customer identity will be checked by application logic. Keep these two identities separate on your drawing. One belongs to the service at the other end of a connection, the other to the customer acting through a session. TLS 1.3 handshake and record protection, RFC 8446

Route the message to the order handler

Once the protected connection is ready, the browser sends the method, target, headers and body. The POST method asks the target to process the enclosed data. The Content-Type header tells the receiver how to interpret those bytes. In this shop it says application/json. The session cookie travels as a header, separate from the product fields. A reverse proxy matches the hostname, forwards the request to the order service, and assigns a request identifier, r17. That identifier lets the operator connect observations made along this request’s journey without recording the customer’s cookie.

The application router selects the handler registered for POST /orders. A path by itself is insufficient. A shop can expose GET /orders to list a customer’s purchases and POST /orders to create one. If your test opens /orders in the address bar, the browser ordinarily makes a GET. An empty list on that page is therefore a poor test of whether the creation handler works. Inspect the actual method and target of the form submission. Then look for r17 at the proxy and at the application. Seeing it at both boundaries narrows the search substantially.

Turn two input fields into one durable fact

First the handler reads the session and identifies customer 37. It parses the JSON, checks that the quantity is a positive integer, and looks up N7. Suppose the shop stores amounts in fils and has enough stock. Its price record contains 2,500 fils per notebook. Multiplication gives 5,000 fils for two, or AED 50.00. The handler prepares an order header with customer 37 and an order line with quantity two and the captured unit price. Keeping that price on the line lets tomorrow’s receipt explain today’s purchase even if the shop changes its catalog.

In our example the service writes both records in one database transaction. If the line cannot be inserted, the transaction rolls back. A customer should never see an empty order header reported as a successful purchase. When the commit succeeds, order 8142 and its line have become the shop’s record of the purchase. A log line saying “starting insert” is weaker evidence than a committed row. A response assembled in memory before the commit is weaker still. Place a pencil mark here on your drawing. Everything after the mark can fail while the order continues to exist.

Return enough information for the next screen

The application sends 201 Created, a Location header with /orders/8142 and a JSON body containing the order number, status, currency and total. The proxy relays the response. The browser uses the returned identifier to show “Order 8142 received, AED 50.00.” It can later request the order detail using the supplied location and the customer’s session. A 201 identifies successful resource creation. It does not say that the goods have shipped, that a payment was captured, or even that a person saw the confirmation screen. Those are separate business events. HTTP response semantics and Location, RFC 9110

Evidence from our example What it establishes
Resolver returns 192.0.2.20 The client has a candidate destination.
Proxy logs POST /orders as r17 The request reached the HTTP front door.
Database contains committed order 8142 for customer 37 This purchase exists in the shop’s records.
Browser displays 8142 and AED 50.00 The client received and interpreted enough of the response to render confirmation.

Read a timing trace without blaming the wrong component

Suppose the browser starts at zero milliseconds. DNS ends at 12, TCP connects at 31, TLS finishes at 58, the first response byte arrives at 145 and the response finishes at 148. These numbers are cumulative from the same starting point. The TLS interval is 27 milliseconds, and receiving the last part of the response takes three. The 87 milliseconds between TLS completion and the first response byte include sending the request, network travel, proxy handling, application work and the return trip. Calling that entire interval “database time” would send the investigation in the wrong direction.

Now suppose the service measures 41 milliseconds from handler entry to exit, of which its database operation accounts for 16. Those measurements already sit inside the browser’s larger interval. Adding all three numbers double-counts work. Instead, compare boundaries: which span grew when checkout became slow? A second submission might reuse a connection and show no new handshake. That difference alone does not prove the server got faster. For a fair comparison record whether the connection was warm, use the same request shape, and keep measurement points consistent.

Lose the response, then decide what to do

Disconnect the network just after the pencil mark. The shop commits order 8142 and tries to return confirmation, but the browser times out. There is no HTTP status visible to the shopper. In this version of the shop a second POST can create another order. A request identifier is useful for finding the first attempt, but merely adding an identifier to a log cannot prevent a second purchase. A practical first action is to check the signed-in customer’s order history or reconcile the pending purchase in the service before inviting another submission.

A more capable checkout can give one purchase attempt a stable identifier and enforce uniqueness for it when writing the order. Retrying the same intent can then recover the previous result under a defined contract. Two customers who both buy two notebooks still need separate orders, as does one customer making a deliberate second purchase. The distinction is the intended purchase, not the coincidence of equal product fields. Implementing this properly requires shared rules for storage, expiry and conflicting payloads. For this first lesson, remember the narrower point: a timeout is an observation made by a waiting client, not a database verdict.

اقرأ الدرس بالعربية

Exercise: identify the last proven step

A customer sees a timeout. The proxy recorded r17, the handler recorded “validated,” and a database query finds order 8142 with a single N7 line with quantity two, at 2,500 fils each. The browser has no response headers. Write three short sentences: what happened for certain, what remains unknown, and what the support agent should do next. Then change the evidence by removing the committed order and retaining only the validation message. Which sentence must change?

Answer. With the committed row tied to this attempt, the shop recorded a purchase worth AED 50.00. The available evidence does not establish that the confirmation reached the browser. Retrieve the existing order for the authenticated customer and present its details before considering any repeat submission. With only the validation message, persistence is unknown. Find the transaction outcome or reconcile the purchase attempt before declaring that it succeeded or failed. A correct answer ties each conclusion to an observation at the boundary that can actually prove it.

YOUR TAKE

What did you think?

Choose one reaction for this article.

Was this useful?

A cookie helps limit repeat responses. Your feedback is private.

Share this noteLinkedIn ↗X ↗Email ↗

Keep exploring.

Software Architecture9 min read

Design Your First Resource API

Design and test an order API that creates a purchase, retrieves its original receipt and tells a shopper exactly how to fix an invalid quantity.

Read article ↗