Highlights

Contents

BACKEND ENGINEERING / UNIT XII / FIELD GUIDERealtime, uploadsand searchWebSockets, object storage, inverted indexes and vectorsobject storagebiryanipush, store, findRealtimepolling, SSE, WebSocketsScalefan-out, presence, millionsUploadspresigned URLs, validationSearchBM25, engines, vectors
Before we start

How to read this chapter

Most of this series has been about a request that arrives, does a little work and leaves. This unit covers three things that break that shape: news that the server must push to a client that did not ask, files too large to pass through an API, and queries that a database index cannot answer well.

Parts I to IV are about realtime. They compare polling, long polling, server-sent events, WebSockets and WebTransport, open the WebSocket protocol, deal with authentication, ordering and slow clients, and then scale connections across servers with fan-out, presence and reconnect storms. Parts V and VI are about files. They cover how uploads arrive, how to validate them without trusting anything the client says, and why large files should go straight to object storage through presigned URLs. Parts VII to X are about search, from the limits of LIKE through analyzers, inverted indexes and BM25 to search engines, embeddings, HNSW and hybrid retrieval. Part XI follows one evening’s tracking, upload and search.

Each section starts from a Wren situation, explains the mechanism, works the numbers and then shows a figure. Picture this boxes give analogies, notes add detail, Watch out names real mistakes, and Interview lens gives an answer to say aloud. In one breath closes each part.

By the end you should be able to choose a realtime transport and defend it, design a WebSocket service for a million connections, design a safe upload path, compute a BM25 score by hand, and explain why hybrid search beats either keywords or vectors alone.

The running system

Meet Wren

Wren is the illustrative food-ordering service from earlier units. These are the numbers this unit uses. All are assumptions chosen for readable arithmetic, not measurements.

Setting Value What it controls
Active orders being tracked 50,000 at peak, each about 40 minutes with 5 status changes Realtime load
Realtime connections up to 200,000, about 20 KB of state each WebSocket scaling
Couriers online 5,000, heartbeating every 10 s Presence
Photo uploads 500 per minute, about 5 MB each, over 10 Mbit/s uplinks Upload path
Large uploads restaurant videos up to 5 GB Multipart upload
Menu items 100,000, average description length 20 terms Search
Embeddings 768 dimensions, 4-byte floats Vector search
Search shards 10 Query latency

The main flows in this unit are user 42 tracking order 124 live, a customer uploading a photo of their biryani, and a search for “chicken biryani”. Part XI follows all three.

The map

What is inside

Three kinds of work that do not fit one request and one response: pushing news, moving files and finding things.

CHAPTER ATLAS / FOLLOW THE READING PATHCHAPTER ATLAS / FOLLOW THE READING PATH1Realtime options2The WebSocket protocol3Realtime applicationconcerns4Scaling realtime5File uploads6Object storage7Searching the database8Full-text search9Search engines10Vector and hybrid search11Track, upload and searchend to end
  1. 01Realtime optionsSections 1 to 4. We compare the five ways a server can get news to a client as it happens.
  2. 02The WebSocket protocolSections 5 to 7. We open the WebSocket protocol, from the HTTP request that starts it to the frames that carry messages and the codes that end it.
  3. 03Realtime application concernsSections 8 to 10. We handle the problems that appear once a connection carries real users' data.
  4. 04Scaling realtimeSections 11 to 14. We grow a realtime service from one server to many, and towards a million connections.
  5. 05File uploadsSections 15 to 17. We accept files from users without letting them crash the server, fool it about what they uploaded, or write outside where they should.
  6. 06Object storageSections 18 to 21. We store files in object storage and keep them out of the application server entirely.
  7. 07Searching the databaseSections 22 to 23. We start search where most products start, with the database they already have.
  8. 08Full-text searchSections 24 to 26. We build up the ideas behind every search engine, from how text becomes terms to how documents are ranked.
  9. 09Search enginesSections 27 to 29. We run search as its own system, kept in step with the database.
  10. 10Vector and hybrid searchSections 30 to 32. We add search by meaning to search by words.
  11. 11Track, upload and search end to endSections 33 to 33. We follow one evening in the app that uses all three parts of the unit at once.
  12. +Interview prepInterview question bank, graded exercises and worked solutions.