Wrap Up
In this chapter, we presented a design that supports a nearby friends feature. Conceptually, we want to design a system that can efficiently pass location updates from one user to their friends.
Some of the core components include:
-
WebSocket: real-time communication between clients and the server.
-
Redis: fast read and write of location data.
-
Redis pub/sub: routing layer to direct location updates from one user to all the online friends.
We first came up with a high-level design at a lower scale and then discussed challenges that arise as the scale increases. We explored how to scale the following:
-
Restful API servers
-
WebSocket servers
-
Data layer
-
Redis pub/sub servers
-
Alternative to Redis pub/sub
Finally, we discussed potential bottlenecks when a user has many friends and we proposed a design for the “nearby random person” feature.
Congratulations on getting this far! Now give yourself a pat on the back. Good job!
Chapter Summary
Reference Materials
- Facebook Launches “Nearby Friends”: https://techcrunch.com/2014/04/17/facebook-nearby-friends/
- Redis Pub/Sub: https://redis.io/topics/pubsub
- Redis Pub/Sub under the hood: https://jameshfisher.com/2017/03/01/redis-pubsub-under-the-hood/
- etcd: https://etcd.io/
- Zookeeper: https://zookeeper.apache.org/
- Consistent hashing: https://www.toptal.com/big-data/consistent-hashing
- OpenStreetMap: www.openstreetmap.org
- Erlang: https://www.erlang.org/
- Elixir: https://elixir-lang.org/
- A brief introduction to BEAM: https://www.erlang.org/blog/a-brief-beam-primer/
- OTP: https://www.erlang.org/doc/design_principles/des_princ.html
Finished reading?
Mark it complete to track your progress.