The architecture is usually a replicated log. Clients send commands to a leader. The leader assigns each command a position in the log (1, 2, 3, ...) and replicates that log entry to the followers. Once a majority of replicas have stored an entry durably, the entry is committed and can never be lost or reordered. Each replica then applies committed entries to its local state machine strictly in log order.
Two pieces have to hold together. First, the consensus layer guarantees that all replicas agree on the same log: the same commands at the same indexes. Second, the state machine must be deterministic so that applying that agreed log produces identical state everywhere. If a developer sneaks in a call to the system clock or a random generator inside the command handler, the replicas drift apart and the whole guarantee breaks. Real implementations push nondeterministic values (timestamps, IDs) into the command itself before it enters the log, so every replica sees the same value.
Because replaying the full log from the beginning would take forever, systems take periodic snapshots of the state machine and truncate the old log. A recovering or newly added replica installs the latest snapshot, then replays only the log entries that came after it.
Failover is the payoff. If the leader dies, the consensus protocol elects a new leader from a replica that has the most up-to-date committed log. Since that replica already holds the same state, it can start serving immediately. Clients see a brief pause, not data loss.