Twitter Timeline Architecture | Fanout | System Design

Поділитися
Вставка
  • Опубліковано 25 лис 2022
  • In this video I will discuss how Twitter scaled its architecture
    System Design Interview Basics Playlist:
    ► • System Design Intervie...
    AWS Certification:
    ►AWS Certified Cloud Practioner: • How to Pass AWS Certif...
    ►AWS Certified Solution Architect Associate: • How to Pass AWS Certif...
    ►AWS Certified Solution Architect Professional: • How to Pass AWS Certif...

КОМЕНТАРІ • 20

  • @RandomShowerThoughts
    @RandomShowerThoughts 25 днів тому

    this is a great and simple breakdown

  • @rahul_singh_rajput3292
    @rahul_singh_rajput3292 8 місяців тому +5

    if i understand this fan out service.
    then here is my logic.
    Normal User
    (1) action has done -> (2) persist it on db/cache -> (2.5) Add this data into this user cache also -> (3) find and filter users whom to send -> (4) update data in users cache -> (5) users will request data -> (6)data will be fetched from cache.
    Celebrity
    Normal-User(1,2,2.5) same after that don't do anything.
    (3) store the celebrity follower for each user somewhere
    (4) when users request data just fetch data from cache and also fetch celebrity post from (2.5) ( check is the user is following that celebrity. if it is then fetch that post and aggregate in the response) .

    • @azharuddin6096
      @azharuddin6096 2 дні тому

      I don't understand, is there a cache dedicated for each user?

  • @azharuddin6096
    @azharuddin6096 2 дні тому

    I have one confusion. is there a cache dedicated for each user? I mean in the graph it looks like we have dedicated caches for each user. Would really appreciate your help.

  • @osagiedeharrison4865
    @osagiedeharrison4865 Рік тому +5

    Hi nice video and thanks for the explanation.
    How is the fan out operated? Is it a loop of a user N followers, like say we are writing with js, do we for a forEach loop (or anything similiar)?
    And also what's the limit of the fan out method, a million followers? 10k? 100k? e.t.c

    • @ByteMonk
      @ByteMonk  10 місяців тому +4

      In the context of programming or social media systems, "fan out" refers to the operation of distributing or broadcasting content from one source (e.g., a user) to multiple recipients (e.g., followers). The concept is commonly associated with social media platforms, where a user's post is delivered to their followers' feeds.
      The implementation of fan out can vary depending on the platform or technology used. For instance, when working with JavaScript in a web development context, you might use a forEach loop or any other iteration mechanism to distribute the content to each follower. In other programming languages or platforms, different methods might be employed to achieve the same goal.
      Here's an example of how fan out might work with a forEach loop in JavaScript:
      const user = {
      name: "John",
      followers: ["Alice", "Bob", "Charlie", "David", "Eve"],
      post: "Hello, everyone! This is my new post.",
      };
      // Fan out the post to each follower using a forEach loop
      user.followers.forEach((follower) => {
      sendPostToFollower(user.post, follower);
      });
      function sendPostToFollower(post, follower) {
      console.log(`${follower} received the post: ${post}`);
      }
      As for the limit of the fan-out method, it depends on various factors including the platform's infrastructure, server capacity, and database performance. The limit can vary significantly from one system to another. Popular social media platforms such as Twitter are designed to handle millions or even billions of followers for high-profile users. They invest heavily in scalable infrastructure to handle the massive fan-out operations.
      For smaller applications or less resource-intensive systems, the limit might be lower. However, it's challenging to give an exact number as the limit because it can change based on the platform's growth, improvements in technology, and other factors.

    • @nythrox3047
      @nythrox3047 8 місяців тому

      shit answer@@ByteMonk

  • @davidmata3104
    @davidmata3104 Місяць тому

    What exactly is stored in the redis cache?
    I would be storing only the userId as key and an array of postIds like this: {userId : [postId, postId, postId]}
    Then when the user wants to load their timeline I will just search the information of those postIds.
    But probably this approach will still put a heavy load on the Post Database.
    So would you add the whole information of the post in the redis cache?
    like:
    userId: [{postId, postTitle, imageUr},{postId, postTitle, imageUr},{postId, postTitle, imageUr}]

  • @showbikshowmma3520
    @showbikshowmma3520 Рік тому +1

    brother let's say like wanna build an architechture similar to the twitter for my startup. so now my question is who will be responsible to create the architechture for whole webapp + native apps? software engineer? devops who will create?

    • @ByteMonk
      @ByteMonk  Рік тому +3

      For a startup you would usually need a Product Owner or Business partner who can explain the MVP (Minimal Viable Product) features for the initial launch, they would partner with Technical Architect, who typically must have breadth of tech knowledge

    • @epicujjwal
      @epicujjwal Рік тому

      system architect?

    • @ByteMonk
      @ByteMonk  Рік тому +1

      @@epicujjwal sorry, my intention with this video was to highlight fanout, a basic element in system design. Please checkout my playlist in description for full system design videos

    • @epicujjwal
      @epicujjwal Рік тому +1

      @@ByteMonk sure, will have a look
      btw thanks for your efforts

    • @Faheem1988
      @Faheem1988 6 місяців тому

      anyone capable of creating such system design shouldn't be stuck in job titles, developers and software engineers can do it. they should think about the edge cases of a system.

  • @s_konik
    @s_konik Рік тому +2

    Hybrid approach isn't clear. As I understand it should somehow avoid fanout writes to inactive users to reduce time and fill redis cache when this inactive user signs in and opens his feed tab. The other thought I found on the internet is that it's possible use read strategy only for users who are subscribed to users with millions of followers.

    • @ByteMonk
      @ByteMonk  Рік тому +4

      Thanks for the feedback, by hybrid approach I meant, if a person having too many followers tweets something, then fanout doesn’t occur for them at all. The tweets of such popular users (such as lady gaga) are merged into the timeline only when some regular users requests the homepage.

    • @ByteMonk
      @ByteMonk  Рік тому +2

      www.infoq.com/presentations/Twitter-Timeline-Scalability/

    • @s_konik
      @s_konik Рік тому +2

      @@ByteMonk thanks for clarifying and the link

    • @baseball-4ever
      @baseball-4ever Рік тому

      @@ByteMonk the hybrid approach seems not updating lady Gaga’s tweet to my home timeline, even after I refresh it? Or perhaps the timeline update request from followers is handled in a separate process instead of fanout?

    • @RandomShowerThoughts
      @RandomShowerThoughts 25 днів тому

      @@baseball-4ever so as I understand it, when we read the home timeline, we'd check for any celebrity tweets, get those, and then merge into the home timeline, and then return the response