Sobes.tech
Junior

What is replication in the context of databases and applications?

sobes.tech AI

Answer from AI

Replication is the process of creating and maintaining multiple copies of database data or application state on different servers.

Goals of replication:

  • High Availability: When one server fails, other replicas can continue to serve requests.
  • Scalability: Read requests can be distributed among replicas, reducing the load on the primary server.
  • Geographical Distribution (Disaster Recovery): Replicas can be located in different data centers to protect against local failures.
  • Latency Reduction: Users can read data from the nearest replica.

Types of replication:

  • Synchronous: Changes are written to all replicas before the transaction is acknowledged to the client. Ensures strong consistency but may increase write latency.
  • Asynchronous: The transaction is acknowledged to the client after being written to the primary server. Replicas are updated later. Provides higher write performance but may lead to temporary data inconsistency.

Replication modes:

  • Master-Replica (or Master-Slave): One replica (master) handles all write operations, while others (replicas) only read, receiving changes from the master.
  • Multi-Master: Multiple replicas can handle write operations. Requires conflict resolution mechanisms.

In the context of applications, replication can refer to creating multiple instances of an application (services) for the same purposes: increasing availability and scalability. For example, running multiple pods in Kubernetes, each being a replica of the same service.