CSE Roadmap

Specialist tier · about 5 hours · 7 parts

Part 4 of 7 · 2 min read

First design

Location, navigation and tiles.

Location service. The phone records its location every second and keeps the points in a buffer. Every 15 seconds it sends the batch to the server over HTTP with keep-alive: a list of latitude, longitude and time. The service stores each point in a write-friendly store such as Cassandra, and also writes it to a stream (Kafka). The stream feeds other services (section 4).

The store uses user_id as the partition key and time as the sort key. The latest point of one user and a time range are both quick to read. Locations go stale at once, so availability matters more than strict consistency.

Navigation service. The phone asks for a route with an origin and destination. The service geocodes both, asks the route planner for routes, and returns the best few. A small delay is fine, but accuracy is key.

Map rendering (the two options).

  1. Build tiles on request. The server draws each tile when asked. There are too many combinations, the server load is high, and caching is hard.
  2. Pre-built tiles on a CDN. Each tile is a static file named by its geohash and zoom level. The client works out the name from its location and zoom level and asks the CDN. A CDN miss fetches from object storage, caches it, and later requests (even from other users) are served nearby.

The book chooses option 2. Static, shared files are cacheable and fast.

Who works out the tile name? If the client does it, the geohash method is hard-coded in every app, and changing it needs an app update. Another way is a map tile service: the client sends its location and zoom, and the service returns the URLs of 9 tiles: the one to draw and its 8 neighbours. The extra call buys flexibility.

Vector tiles. Instead of pictures, send the paths and shapes, and let the phone draw them (WebGL). Vector data compresses better, and zooming looks smooth, with no stretched pixels.

A worked example (made up). A driver at zoom 15 moves into a new square. The phone asks the map tile service for 9 URLs, and fetches 3 new tiles it does not have, since 6 are already stored. At 100 KB each, that is 300 KB over the network.

Common mistake

Drawing tiles when each user asks. Nothing is shared and the CDN cannot help. Map tiles change rarely, so build them ahead and serve them as files.

Check yourself: 1. Where does the location service store its points? 2. Why does the CDN help with static tiles? 3. What does the map tile service return?