Case study demo

Nearby friends

Stream location updates and find friends within a radius.

An interactive demo of how this system behaves. It runs in your browser.

Case study · Live model

How nearby friends behaves

40 people move about a town, and each has 6 friends. Every phone keeps one connection open to the server and sends its place every few seconds. The server passes each update to the friends who are online. Change how often phones send, or cut the signal of some phones, and watch the maps.

Try it

Lab time 3.0 s
keeppublishPhones, 40 of 40 onlinePhones40 of 40 onlinesend a place every 5 sConnection servers, one open connection eachConnection serversone open connection each9.3 updates a secondPlace cache, 28 newest placesPlace cache28 newest placesone for each phone onlineChannels, a list of who listensChannelsa list of who listens56 messages a secondFriends' phones, 6 listen to eachFriends' phones6 listen to each18 shown as nearby
  • Phones — 40 of 40 online — healthy — send a place every 5 s
  • Connection servers — one open connection each — healthy — 9.3 updates a second
  • Place cache — 28 newest places — healthy — one for each phone online
  • Channels — a list of who listens — healthy — 56 messages a second
  • Friends' phones — 6 listen to each — healthy — 18 shown as nearby
  • A phone sends its place (1 dot for 4 phones)
  • The place is passed on to friends
Places are off by
5 m
on average; 20 m at most
Messages sent on
56a second
9.3 updates, each to up to 6 friends
Nearby, on the maps
18
friends shown within 500 m
Wrong about nearby
8
Watch: shown near but far, or far but near
Gone, still on a map
0
people with no signal; on 0 maps, 0 as nearby
Phones online
40/ 40
every phone has a signal

Numbers add up:28 updates sent = 28 at the server + 0 on the way · 168 messages = 168 delivered + 0 on the wayThe lab checks this sum as it runs, so a counting mistake would show here.

Controls

Updates
every 5 s

The new gap starts after each phone's next update.

Phones and the server forget a place when two more updates should have come since.

People

Your friends

FriendMoves byOn your mapIn truthOff byAge of the placeYour map says
Person 2bike709 m711 m13 m1.6 stoo far
Person 40bike770 m769 m1 m0.1 stoo far
Person 3foot–500 m––no place yet
Person 39foot800 m798 m3 m1.9 stoo far
Person 4foot1,340 m1,338 m2 m1.5 stoo far
Person 38foot1,221 m1,225 m4 m2.8 stoo far

You are person 1. "On your map" is the distance to the last place each friend sent. A friend counts as nearby within 500 m.

How far off places are (metres), and messages a second
Off by (m)Messages a second
02550751001s2s3s
Show data table
TimeOff by (m)Messages a second
1s0.448
1s1.354
2s1.964
2s3.154
3s4.752.8
3s5.256

What just happened

Nothing yet. Start traffic or run an experiment.

What this model simplifies
  • There are 40 people in a town 2 km wide, and each has 6 friends. A real service has many millions of people, so it runs many connection servers and must find the one that holds each friend's link.
  • People walk at 1.4 m a second or ride at 8, and turn every 5 to 15 seconds. Real phones send less often when they are still, and more often when they move fast.
  • A phone gets every update of every friend, and works out the distance itself. Real services often drop an update on the server when the two friends are far apart.
  • The page counts messages, not battery. On a real phone the radio is what costs, which is why the gap between updates matters so much.
  • A phone that closes the app in the normal way says goodbye, and the server takes it off the maps at once. The button here cuts the signal, which is the hard case: no goodbye arrives.
  • Nobody hides their place. Real apps let a person share with some friends only, or stop sharing for a while.

Design it

Live places that are close enough, at a cost the server can take

Forty people walk or cycle around a 2 km town, and each phone sends its place to the server. The server shows each person which friends are within 500 m. Like a ride-hailing app showing nearby drivers, it must be close to the truth without flooding the server. Pick how often phones send, and what the server does with places that stop coming.

The goals

  • A friend's place on screen is at most 15 m off, on average.
  • The server gets at most 10 place updates a second.
  • After 8 phones lose signal, none of them is still shown as nearby.
Each phone sends its place every
A place that has stopped coming

The check runs the same engine as the demo on this page for 40 simulated seconds under each condition, with a fixed seed, so a design always gets the same result. There is no score: each goal passes or fails.