Skip to content

How to design a live map of points (frontend)

The first sections are free. The deep dives, level expectations and quiz are part of Pro.

On this page
Asked at
Practice this question

The problem

A world map on an internal dashboard where each new sign-up is a point, new ones land while someone looks, and the view goes from the whole globe to one street. The design turns on one gap: there are about a hundred times more points than a page can draw, so zoom has to be part of each request. The server answers with grouped counts when the view is wide and with raw points when it is narrow, a single canvas draws whatever comes back, and new sign-ups are folded into that picture in batches rather than one redraw at a time. One candidate's report on FrontendLead of a LinkedIn onsite describes this map as the design round and says they could not tell what was being judged. Our advice: lead with the gap between the data and the screen, then the live path, and put a number on each.

Clarifying questions

AskWhy it mattersA typical answer

How many sign-ups are there in all, and how fast do new ones arrive on a normal day and in a burst?

The first number decides whether the browser can ever hold the data; the second decides how the live path has to be built. A map of a few thousand points is a different question from one of a hundred million.

Say 100,000,000 points in all. No burst rate is given: assume a campaign can bring far more in a minute than a normal day does, and design the live path so that a burst changes batch sizes rather than redraw frequency, with a buffer cap and a refetch as the fallback when it is exceeded.

When the view is wide, do people need exact counts, or is a heat map enough?

Clusters with counts can be clicked and read; a heat map is calmer but has no discrete groups to click without extra hit-testing. The choice changes what the server returns and what the canvas draws.

Clicking a group to see what is inside is a requirement, so clusters with counts are the default. A heat map is a fair alternative to mention for the widest zooms.

Is the base map (the streets and coastlines) ours to build, or do we use a map library?

Building a base map is a separate, large problem. Using a library means our work is the data layer on top of it and the requests behind it.

Use a library. Drawing the base map is out of scope; you own the layer of points and clusters, the requests, the cache and the live connection.

Which devices and browsers? Is this desktop dashboards or phones too?

Memory and GPU budgets differ a lot between a desktop dashboard and a phone, which changes how much the client may keep in memory and how large an answer may be.

Internal dashboards, mostly desktop, but the targets stay the same: 60 frames a second while moving and a response within 200 milliseconds.

What does live mean here: each sign-up within a second or two, or a refresh every so often?

Within seconds calls for an open connection and batching; a refresh every few minutes could be a timer and a button.

Within a few seconds. Batching several sign-ups into one update is fine; making someone press refresh is not.

What shows on a click, and does anyone have restricted access to some sign-ups?

A click on a point needs a details call; clicking a cluster needs a plan for thousands of members. Access rules would change what the server returns.

A click on a point fetches GET /points/{id} and shows a few fields. Who may see which sign-ups is out of scope today.

The requirements menu

RequirementScopeWhy

Show every sign-up as a point on a world map

Core

The product itself. How it is drawn at each zoom is the whole design.

Add new sign-ups to the map as they happen

Core

Live arrival is what makes this more than a chart; it brings the connection, the buffer and the merge.

Zoom from the whole world down to one street and pan around

Core

The zoom range is why one answer shape does not serve both ends: grouped counts for a wide view, single points for a narrow one.

Click a point or a group of points to see what is there

Core

It settles the choice of clusters over a heat map for wide views, and it adds the details call for one point.

Offer a heat map as an alternative view when zoomed out

Optional

Take it if the interviewer asks what the map looks like for the whole world: a heat map hides clutter. Leave it as a mention; clusters already satisfy the click requirement.

Filter the map to a time range, such as the last hour

Optional

Take it if time allows: it shrinks the data the server has to group and is a natural dashboard control. It adds a parameter to the request and to the cache key.

Show the current view in the URL so a link reopens the same place

Optional

Take it for an internal dashboard where people share links. It costs little: bounds and zoom already exist as state.

Show a banner and keep the last picture when the live connection is down

Optional

Take it: a map that silently stops updating looks live when it is not. It needs reconnection and a refetch on return.

Hover a cluster to read its count without clicking

Optional

Take it if there is time; it needs hit-testing against the canvas, which is also what a click needs.

Drawing the base map itself

Out of scope

A map library provides it. Our work is the layer on top.

Searching for a place by name

Out of scope

Geocoding is a service of its own; the map accepts a view, not a query.

Who may see which sign-ups

Out of scope

Authorization belongs to the server and the dashboard shell, not to the map layer.

Playing back past days

Out of scope

Playback changes the data model to time slices; it comes up as a curveball and is covered as a variant.

Exporting the visible points as a file

Out of scope

A server-side export; it has nothing to do with drawing or live updates.

Non-functional requirements

RequirementWhat it forces

Panning and zooming stay at 60 frames a second

Main-thread work during a move has to fit the frame budget, which in this design means parsing and grouping move to a worker and there is no per-point DOM work. Points live in typed arrays on a canvas or WebGL layer, and movement redraws what is already there instead of waiting for the network.

The page never loads the whole data set, only what the view needs

Bounds and zoom go into each request, the server groups points before sending when the view is wide, and the client keeps a bounded cache rather than a copy of the data.

A burst of sign-ups never freezes the map

New sign-ups are received for the visible area, held in a buffer, and merged into the picture at most once a frame. At wide zoom a burst changes counts, not the number of things drawn.

A pan, a zoom or a click answers within 200 milliseconds

The first paint after a move uses the previous picture, scaled, so the response does not depend on a round trip. Requests are sent once the view rests, stale ones are aborted, and recent answers are kept under an area-and-zoom key, so moving back is instant.

Estimates

QuantityWorkingResultWhat it sizes

Points in all against points a page can draw smoothly

100,000,000 points in the data set / about 1,000,000 that deck.gl reports at 60 frames a second on a 2015 laptop = 100

About 100 times more points than a page can draw

Why grouping must happen before the data reaches the browser. Even the 10,000,000 mark, where the same guide reports the frame rate falling to 10 to 20 a second, is a tenth of the data.

Time budget for one frame

1,000 ms in a second / 60 frames = about 16.7 ms

About 16.7 ms a frame

Everything the main thread does during a move, including a merge of new sign-ups, must fit inside this, which is why parsing and grouping go to a worker and redraws are tied to frames.

Merges of live sign-ups a second

1,000 ms / one merge per 200 ms = 5 merges a second at most

At most 5 merges a second, however many sign-ups arrive

The buffer between the connection and the canvas: a burst changes how big each batch is, not how often the canvas redraws.

Requests during a one-second drag if each movement event sent one

Assume one movement event a frame: 60 frames a second x one second = 60 requests

About 60 requests for one drag, most for views already left

Why requests go out when the view rests and the in-flight one is aborted on the next move.

Memory for a full view of raw points as typed arrays

Two 32-bit floats a point = 8 bytes; 1,000,000 points x 8 bytes = 8 MB

About 8 MB of positions for a million points

What a worker hands to the canvas per answer when positions are compact arrays rather than one object per point; also a scale for the cache cap.

Core entities

EntityWhat it holds

Point

One sign-up at one place and time; drawn as a dot at close zoom and opened on click.

Cluster

A group of nearby points the server built for one zoom level; drawn as a circle with a count.

View

What the map shows right now and which answer it is showing.

Client cache

Recent answers kept so that moving back to a view seen a moment ago needs no request.

Live batch

Sign-ups that arrived since the last merge, waiting for the next frame.

The API

EndpointNotes

GET /points?bounds&zoom → { clusters, points, version } with points only at close zoom

The one data call. Bounds are the view, zoom picks the shape of the answer: clusters for a wide view, raw points for a narrow one. version lets the client tell answers from different moments apart and goes into the cache entry.

GET /points/{id} → the details for one point

Called on a click at close zoom. Keeping details out of the bulk answer keeps each point down to a position and an id.

Live connection, server to client: new points, each with its place and time, batched

A WebSocket in this design. Batches carry the version they bring the client up to, so a gap after a dropped connection is detectable.

Live connection, client to server: the area and zoom now in view

Sent when the view rests, so the server pushes sign-ups for that area and, at wide zoom, can send count changes instead of points.

The high-level design

clickbounds and zoomclusters orpointsGET /points/idMap viewDetail panelServerCanvas layer

Step 1 of 4

Ask by view, draw on a canvas

Start with the shape that already respects the scale: the map view sends its bounds and zoom, the server answers with clusters for a wide view or points for a narrow one, and a single canvas layer draws them. A click at close zoom opens a detail panel that fetches one point by id. This already avoids the two big mistakes, a download of the whole set and a page element per point. It still fetches on each movement, keeps nothing, and parses each answer on the main thread.

pan, zoomview at restabortmissclusters orpoints, versiontyped arraysstorehitarea and zoombatched sign-upsonce a frameclickGET /points/idMap viewView controllerAnswer cacheStale requestServerBackgroundworkerCanvas layerLive connectionIncoming bufferDetail panel
The whole design

What breaks first

The deep dives

Far more points than the page can hold. Someone opens the map at world zoom, so the view contains every sign-up there has ever been. What does the page request, what comes back, and what does the canvas draw?

A concept that helps here: Canvas or the DOMA concept that helps here: Tile pyramids and zoom levelsA concept that helps here: Geospatial indexing

New sign-ups arriving live. A campaign launches and sign-ups flood in from one country, far more in a minute than a normal day brings. How does each one travel from the server to a change on the map, and what keeps the map moving while they do?

A concept that helps here: Batching UI updatesA concept that helps here: WebSockets, server-sent events and pollingA concept that helps here: Reconnect and resume

Panning and zooming. Someone drags the map across an ocean, zooms into a city, then straight back out, all inside a couple of seconds. What does the page request along the way, and what is on screen while the answers travel?

A concept that helps here: Debounce and request cancellationA concept that helps here: Client caching and normalized stores

Concepts this guide uses

Sources

  1. deck.gl: Performance optimization
  2. Mapbox supercluster README
  3. MDN: Using Web Workers
  4. MDN: Transferable objects
  5. web.dev: Web Vitals
  6. MDN: AbortController
  7. MDN: WebSocket
  8. MDN: OffscreenCanvas
  9. MDN: Window.requestAnimationFrame()
  10. MDN: Optimizing canvas
  11. FrontendLead Discuss: Interview frontend virtual onsite at LinkedIn
Sign in to report a mistake