Designing a Micro-blogging Platform — Scalable, Available, and Consistent

Creating a user-friendly micro-blogging platform is like building a digital highway. This blog post explores the secrets behind making it handle lots of users, stay available, and organize information

Mentor

Blog

Introduction: 

Microblogging platforms have become a crucial part of our online social interactions. In this blog post, we will delve into the design considerations and architecture for creating a highly scalable, available, and consistent micro-blogging platform to meet the demands of a large user base.

Functional Requirements:

  1. User Actions:
    1. Users can create public or followers-only posts.
      1. Following other users.
        1. Like and comment on posts.
          1. Reply to comments.
            1. Edit and delete your own comments.
              1. Sort comments based on time or likes.
                1. View trending tweets/posts.

                Non-functional Requirements:

                1. High Availability:
                  1. The system should be available 24/7 to accommodate users from different time zones.
                  2. Low Latency:
                    1. Users should experience minimal latency when creating and viewing posts.
                      1. Eventual consistency is acceptable for some features.

                      Capacity Estimations:

                      1. Daily Active Users (DAU):
                        1. 10 million users.
                          1. Estimated Queries Per Second (QPS): 115.
                          2. Posts:
                            1. 5% create posts, 30% engage with posts, and the rest are viewers.

                            Storage Estimations:

                            • Post Storage:
                              • 5TB per day.
                              • Total storage for 5 years: 9125TB.
                            • Post Storage:
                              • 5TB per day.
                              • Total storage for 5 years: 9125TB.

                            Database Design:

                            1. User Table (SQL):
                              1. Unique identifier (Mobile/Email).
                                1. First/Last Name.
                                2. Post Table (SQL)
                                  1. Post ID.
                                    1. User ID.
                                      1. Comment ID.
                                        1. Media link (Stored in GCS/S3)
                                        2. Comment Table (SQL):
                                          1. Comment ID.
                                            1. User ID.
                                              1. Comment content.
                                              2. Reply Table (SQL):
                                                1. Reply ID.
                                                  1. Comment ID.
                                                    1. Reply content.
                                                    2. Connection Table (SQL):
                                                      1. User ID.
                                                        1. Followed User ID.
                                                        2. Like Table (HBase):
                                                          1. User ID.
                                                            1. Post ID.
                                                              1. Like count.

                                                              Data Storage:

                                                              1. GCS/S3:
                                                                1. For static media associated with posts.
                                                                2. Feed DB:
                                                                  1. Batch job-based storage for the user feed.

                                                                  APIs:

                                                                  1. Create Post:
                                                                    1. Endpoint: /create_post
                                                                      1. Parameters: Token, Message, Media.
                                                                        1. Returns: JSON.
                                                                        2. Follow:
                                                                          1. Endpoint: /follow
                                                                            1. Parameters: Token, UserID.
                                                                              1. Returns: Boolean.
                                                                              2. Like:
                                                                                1. Endpoint: /like
                                                                                  1. Parameters: Token, PostID, Count.
                                                                                  2. Comment:
                                                                                    1. Endpoint: /comment
                                                                                      1. Parameters: Token, PostID, Comment.
                                                                                      2. Reply:
                                                                                        1. Endpoint: /reply
                                                                                          1. Parameters: Token, CommentID, Reply.
                                                                                          2. Update:
                                                                                            1. Endpoint: /update
                                                                                              1. Parameters: Token, PostID, Operation (Edit/Delete).
                                                                                              2. Get Feed:
                                                                                                1. Endpoint: /get_feed
                                                                                                  1. Returns: JSON (trending with posts).
                                                                                                  2. Search:
                                                                                                    1. Endpoint: /search
                                                                                                      1. Returns: User/Post information.

                                                                                                      High-Level Design:

                                                                                                      Image

                                                                                                      Conclusion:

                                                                                                      Designing a micro-blogging platform involves meticulous planning to handle the immense user base and their interactions. By incorporating scalable database structures, distributed storage, and efficient APIs, we can create a system that fulfills the functional and non-functional requirements, providing users with a seamless and engaging experience.