
In database replication, master-slave replication is also known as active/passive or leader-based replication. There are two types of nodes in this architecture: Master and slave. The single master (leader) node works as the primary database, while one or more slave (follower) nodes maintain copies of the Master’s data.

In distributed systems, database replication is the process of keeping multiple copies of the same data in different servers (replicas) so that if one server goes down, other servers can continue to serve data without any interruption or downtime. Database replication provides several advantages like high performance, availability, and reliability.

Caching is the process of storing the results of a request in a cache or a temporary storage location so they can be accessed more quickly. In this blog, we have discussed: 1) How caching works? 2) Real-life examples of caching 3) Types of caching 4) Cache eviction policies 5) The idea of cache invalidation 6) Advantages and disadvantages of caching.

Write-behind (write-back) caching pattern is similar to the write-through cache with one big difference: data written to the cache is asynchronously updated in the database. In other words, application will first write to the cache and cache will write to the database after some delay. This asynchronous update will help us to reduce the latency of write operations.

In write-around caching, when application write new data, it bypasses the cache and directly write it to the database. So data is not stored in the cache during the write operation. When there is a cache miss during a read request, cache will fetch data from the database, update its entry and return data to the application.

Refresh-ahead cache asynchronously refreshes the most recent version of data from the database before the expiration. The refresh operation is done on a consistent time interval by some background job. So refresh-ahead cache ensures that data that are likely to be accessed soon are available in the cache before they expire. This will help to reduce the read latency of frequently accessed data.