How Does Facebook Store Friends in its Database?

preview_player
Показать описание
This sql tutorial will act as one of Facebook tutorials.

This Meta tutorial will walk you through how Meta stores friends in its MySQL database management system.

This mysql tutorial will tell you that Facebook, or Meta, uses MyRocks to power its infrastructure.
MyRocks is MySQL with a RocksDB storage engine, and in this mysql tutorial for beginners we'll look at how does Facebook maintain a list of friends in their MySQL-based RocksDB database.

From a logical perspective, it's all pretty basic.
Picture a table with three columns - id1, id2, and time.
There is a primary key on the (id1 and id2) columns, and a secondary SQL index on (id1, time.)

Such a structure allows Facebook (Meta) to quickly check whether id1 is friends with id2, as well as provide a list of X amount of friends.

Facebook database also uses a distributed data store called TAO that caches the entire friend list in the back-end, and although Facebook doesn't maintain a "table for each user", Meta's database is a sharded environment.

As such, each SQL database shard has a "friends" table for the users of that database shard. So, we can say that it all works on a table-per-X-users principle in the database.

Interested in SQL and NoSQL databases? Ways to defend against SQL injection, xss attack, and other attacks? Subscribe to this sql tutorial channel to know all of the answers to your most pressing sql interview questions!

Subscribe to learn more about how databases power popular social media applications, and until next time!

Source of information: Domas Mituzas (Facebook, 2016.)

Music:
Creative Commons — Attribution 3.0 Unported — CC BY 3.0

#facebook #meta #mysql #database #sql #web #webdevelopment
Рекомендации по теме