InfrastructureLesson 3 of 48 min
Geography, latency, and the edge
Where your code sits relative to your users and your data is a design decision.
Physical distance costs time and nothing removes it. A request from Sydney to a server in Virginia takes roughly 200 milliseconds round trip before your code does a single thing. Multiply by the number of round trips a page needs and geography becomes the dominant term.
"The edge" means running code in many locations worldwide so that whichever one is nearest to the user handles the request. For work that needs no central data (redirects, personalisation from a cookie, serving cached content) this is a large, cheap win.
- Static files
Everywhere. This is what a CDN is for and it is nearly free. - Cached pages
Everywhere, with rules about when they expire. - Code that queries the database
Next to the database. - The database
One primary region, close to most of your users.
What to remember
- Distance sets a hard floor on response time.
- The edge only helps for work that does not need central data.
- Keep code that queries the database near the database.
Terms in this lesson
Show field notes toggles a search param the loader reads. With it off, the slow promise is never created, so nothing streams.