SYSTEM-DESIGN
    advanced

    Leader Election (Raft)

    Software Engineer path · lesson 80 of 99
    Node AFOLLOWER
    Node BFOLLOWER
    Node CFOLLOWER

    Elect a leader

    Sequence

    Order a Raft leader election.

    Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.

    1. 1Drop a step here
    2. 2Drop a step here
    3. 3Drop a step here
    4. 4Drop a step here
    5. 5Drop a step here
    5 pieces left to place

    Test your knowledge

    21 questions
    Question 1 of 21
    Score: 0

    What is the purpose of the Leader continuously sending empty messages (Heartbeats) to all Followers in the Raft algorithm?

    The short version

    Raft is like a classroom. The Teacher (Leader) constantly talks (Heartbeats) so the students (Followers) know she is there. If the Teacher leaves the room and stops talking, eventually a student will stand up (Candidate), ask the class if they can be the new Teacher, and if they get enough votes, they take over the class.

    In more depth

    Raft Consensus Algorithm

    In a distributed database, nodes must agree on the state of the data (Consensus). To do this efficiently, most systems elect a single Leader to handle all writes and replicate them to Followers.

    The Election Process

    1.All nodes start as Followers.
    2.The Leader continuously sends empty AppendEntries RPCs (Heartbeats) to all Followers.
    3.If a Follower receives no heartbeats before its internal randomized timer expires, it promotes itself to a Candidate.
    4.The Candidate votes for itself and requests votes from the cluster.
    5.If it receives votes from a majority of the cluster, it becomes the new Leader.

    Interview Questions

    Cockroach Labs
    Google
    Amazon
    Meta
    Google
    Microsoft
    Datadog
    Netflix
    Stripe

    Love this visualization?

    Sign up to track your progress, earn achievements, use the AI assistant, and access your personal learning dashboard.

    100% free • No credit card required