Sobes.tech
Junior — Middle

Explain the concept of replication in data storage systems or databases.

sobes.tech AI

Answer from AI

Replication in storage systems and databases is the process of copying and maintaining up-to-date copies of data on multiple servers or nodes.

Goals of replication:

  • Increased fault tolerance: if one node fails, data is available on another.
  • Improved read performance: requests can be distributed among replicas.
  • Geographical distribution of data to reduce latency.

Types of replication:

  • Master-Slave (Primary-Replica): writes are made to the master, and changes are asynchronously or synchronously copied to slaves.
  • Multi-master: multiple nodes can accept writes, requiring conflict resolution.

Example in a database:

// Pseudocode for writing to master and reading from replica
func WriteData(data string) {
    masterDB.Insert(data)
}

func ReadData(id int) string {
    return replicaDB.Query(id)
}

Replication requires synchronization setup and data consistency management.