Figma has 3 million active users.

Figma has 3 million active users.




Figma has 3 million active users.

https://www.linkedin.com/posts/alexandre-zajac_softwareengineering-systemdesign-programming-activity-7177567333454856192-oP7G?utm_source=share&utm_medium=member_android


Here's how they scaled PostgreSQL to 100x:


๐Ÿญ. ๐—ž๐—ฒ๐˜† ๐—–๐—ต๐—ฎ๐—น๐—น๐—ฒ๐—ป๐—ด๐—ฒ๐˜€:


Figma's database stack scaled almost 100x since 2020, demanding custom scaling efforts.


Initial efforts focused on reducing CPU utilization through vertical partitioning, but this method hit its limits:


The size of some tables reached several terabytes and billions of rows, and the max IOPS supported by AWS RDS was exceeded.


Making sure the system can scale without compromising developer velocity or the complex relational data model Figma relies on, was a tough challenge.


๐Ÿฎ. ๐—œ๐—บ๐—ฝ๐—น๐—ฒ๐—บ๐—ฒ๐—ป๐˜๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐——๐—ฒ๐˜๐—ฎ๐—ถ๐—น๐˜€:


Vertical Partitioning was the initial strategy to manage growth by splitting related tables (e.g., Figma files, Organizations) into separate databases, providing incremental scaling gains.


Horizontal Sharding was adopted to break the limitations of vertical partitioning, with the distribution of data across multiple physical database instances.


Here are the choices they made for horizontal sharding:


- Avoided NoSQL due to the complexity of Figma's relational data model.

- Explored open-source and managed solutions but decided against them due to the need for complex data migrations and the preference to leverage existing in-house expertise on Postgres.

- Selected a colocation strategy minimizing application layer changes, not supporting atomic cross-shard transactions but working around their failures.

- Introduced "colos" for related tables sharing the same sharding key, allowing cross-table joins and transactions within the same shard.

- Implemented DBProxy service for query routing, dynamic load-shedding, and request hedging.

- Utilized logical sharding and Postgres views to de-risk the rollout of horizontal sharding.


In the end, Figma successfully shipped the first horizontally sharded table in September 2023 with minimal downtime and no impact on latency or availability.


By doing this, they also achieved an extended scalability runway for high-write-rate databases and set the stage for sharding more complex databases with numerous tables and code dependencies.


๐Ÿฏ. ๐—”๐—ฐ๐˜๐—ถ๐—ผ๐—ป๐—ฎ๐—ฏ๐—น๐—ฒ ๐—Ÿ๐—ฒ๐—ฎ๐—ฟ๐—ป๐—ถ๐—ป๐—ด๐˜€:


- Incremental progress and maintaining the ability to roll back changes can make or break a migration.


- A detailed understanding of your data distribution and the selection of an effective shard key ensures even data distribution and scalability.


- Using existing expertise and infrastructure (PostgreSQL) while exploring new solutions (like DBProxy and logical sharding with Postgres views in Figma's case) can help you address immediate scaling needs while laying the groundwork for future growth.


Do you use PostgreSQL?


#softwareengineering #systemdesign #programming



Report Page