A map with 10,000+ live pins

System design scenarios Senior Swift 5.9+ iOS 17+ Reviewed By Alok Singh

Pick the fix

The map stutters with 10,000 driver annotations updating every second. Best approach?

Options
Hint 1 of 1

Draw less, update less.

Choose an answer, then open Show answer below to check it.

Show answer

Answer: A Show only the visible region, cluster at low zoom, batch updates by id and throttle while the map moves

Correct. Far less is drawn and updated.

Why not the others?
  • B Increase the update rate for smoother movement. More updates mean more work.
  • C Use bigger pin images. Bigger images cost more to draw.
  • D Recreate all annotations every update. That's the most expensive option.

30-second answer

Never put every pin on the map. Query only drivers in the visible region (plus a margin), cluster them at low zoom, and update positions in batches a few times per second, diffing by driver id and animating moves. Receive updates over a WebSocket filtered by region on the server. For extreme density, draw dots in a custom overlay or Metal layer instead of annotation views.

Practise saying it · 90 s. No recording, just a timer

Design the live map.

Say your answer out loud, then check which of these points you covered:

  • Visible region only
  • Clustering
  • Batched updates
  • Server-side filtering

Deep dive

Throttle updates when the map is moving.

Interpolate positions between updates for smooth movement.

Reuse annotation views and use clustering identifiers.

Stop updates when the map is off screen.

Common mistakes

  • Adding all 10,000 annotations.
  • Applying every socket message immediately.

Senior take & follow-ups

Seniors reduce what's sent and drawn before optimising drawing.

Follow-up questions

Think of your answer first, then open the hint.

  1. How does the server help?

    Show hint

    It sends only drivers in the requested region.

  2. How do pins move smoothly?

    Show hint

    Animate between known positions.

Suggest a fix if something here is wrong or out of date.