- Facebook's goal is to making features and selling ads
- Only scaling if they need to
![](https://i.imgur.com/96eLnos.png)
![](https://i.imgur.com/xNnGzfK.png)
- Multiple Front End Servers
- Still a Single backend database
- Don't have to worry about things like distributed transactions
![](https://i.imgur.com/rGFR6Ub.png)
- Multiple Front End Servers, Multiple Databases Shared
- a-g for database 1, g-q for database 2, q-z for database 3
![](https://i.imgur.com/hqijbnP.png)
- MEMCACHE Servers
get(key, value)
put(value)
- a cache for data that is hit often "hot" data
- but if a MEMCACHE fails, the database will fail
- the database usually only sees a few percent that the caching layers sees!!!
![](https://i.imgur.com/69M64Q0.png)
- Stale data doesn't really matter
- just some pictures from friends from last hour, etc.
- Two datacenters
- Try to avoid cross nation communication
![](https://i.imgur.com/Pc8ujBS.png)
- delete for overwriting, because the data in the cache is stale
- performance by:
- partition
- RAM efficient
- not efficient for hot keys
- replication
- good for hot keys
- few TCP connections
![](https://i.imgur.com/Pc8ujBS.png)
- replication between datacenters
![](https://i.imgur.com/PcPabjq.png)
- sharded database
- multiple clusters
- FE to MC connections is \( O(N^2) \) so have to limit it and make it in clusters
- Regional Pool Cache
![](https://i.imgur.com/lQVpcn2.png)
- a problem where a miss causes other front end servers to overload the database
![](https://i.imgur.com/18aD8dv.png)
- instead use a lease
- a number
- invalidate the lease
- when trying to write note lease is invalid, write is invalid
![](https://i.imgur.com/SKbRrsK.png)
- when deleting, use gutter memcache
![](https://i.imgur.com/4ayacdC.png)
- we get into a data race
- problem - data is out of date forever!
- use lease again