After you click Generate report
Lesson 1 of 3 · One request, end to end · 3 min · Free Watch this lesson freePress a button in an app and a lot happens before the answer shows up. This course follows that trip, so you can design apps that stay quick and correct when thousands of people press at once.
You've used plenty of web apps, and you've written a bit of code. You don't need to know anything about servers or databases yet. We'll bring each piece in when the story needs it.
We'll start with one button click and follow it all the way there and back. Later lessons stay on that same trip. What if we kept a copy of the answer? What if a thousand people clicked at once? And what if one piece just stopped?
The click
Say you run a small bike rental shop, and you use a web app to keep track of your rentals. It's the first of November. You open the reports page, pick October, and click Generate report.
The page doesn't have your rentals. They're stored with the shop, on other computers, so the page has to go and ask.
The request
So the browser sends a request to the shop's server, the computer that runs the app's code. The request starts with the word get. That just means we want to read something. Then comes an address that names the rentals report, and the month we want: October.
The server answers only the requests it has agreed to, each with its own address, and that agreed list is called the app's API. This request is one of them. And look at what travels: a few words asking for October. The rentals themselves stay where they are.
The work
While your page waits, the server reads the request. It doesn't keep the rentals itself, so it asks the database, which stores each rental as one row: a date, a bike and a price.
Its question is short: count October's rentals and add up their prices. The database finds all one hundred and eighty-six October rows, does the sums, and hands the server back the count and a total of seventy-four thousand four hundred rupees.
Nobody had stored that total anywhere. It was worked out from the stored rows, from scratch, the moment you clicked.
The response
Now the server sends a response back to the browser that's been waiting. It carries the count, the total, and the time they were worked out.
The browser drops each value into its place on the page, and your report appears.
Click again
That's the whole trip for one click: a request out, work on stored data, and a response back. Now picture clicking Generate report again a minute later. October hasn't changed. Does the database have to count all one hundred and eighty-six rentals again?
This is the narration of a video lesson from Software System Design. In the video it is animated, and you can pause it to ask a question.