At any moment a Raft server is in one of three roles: leader, follower, or candidate. There is at most one leader, and it handles every client write. Time is divided into terms, which are just monotonically increasing numbers that act as a logical clock. Each term has at most one leader.
When a follower stops hearing heartbeats from the leader for a randomized timeout (often 150 to 300 milliseconds), it bumps the term number, becomes a candidate, and requests votes from the others. A server grants its vote to the first valid candidate it sees in that term. Whoever collects votes from a majority becomes the new leader. The randomized timeouts make it unlikely two candidates split the vote repeatedly.
Once elected, the leader appends each client command to its own log and sends AppendEntries messages to the followers. An entry is committed once a majority of servers have stored it. Only then does the leader apply it to its state machine and reply to the client. Because commit requires a majority, a five-node cluster keeps working with two nodes down, and a three-node cluster tolerates one failure.
Safety comes from a few rules: a candidate can only win if its log is at least as up to date as the majority that votes for it, and entries are never overwritten once committed. This guarantees the elected leader already holds every committed entry, so no acknowledged write is ever lost.