offline limited multi-master in Postgres
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
In PostgreSQL, achieving high availability and scalability often involves implementing multi-master replication strategies. An intriguing subset of this is the "offline limited multi-master" approach. This method allows for multiple sites or servers to act as write nodes, albeit not entirely in real-time. In this article, we will explore the technical underpinnings of offline limited multi-master replication in PostgreSQL, its advantages, potential use cases, as well as its limitations.
Understanding Multi-Master Replication
Multi-master replication allows multiple database nodes to function as masters simultaneously. Each master node is capable of processing read and write requests. This enhances both the scalability and availability of the database system in distributed environments. However, the complexity of maintaining consistency across nodes in real-time makes full-fledged multi-master setups challenging to manage and often excessive for many use cases.
Offline Limited Multi-Master Approach
The offline limited multi-master approach achieves similar objectives to traditional multi-master setups but with a more pragmatic model. Here, multiple nodes can independently accept write operations. The changes are then synchronized between the nodes at specified intervals rather than in real-time. This model opts for eventual consistency, where the system guarantees that, given enough time, all nodes will converge to the same state.
Technical Explanation
- Node Independence: Each site can function independently, making it well-suited for environments where intermittent connectivity is a concern, such as applications in remote locations.
- Synchronization Mechanism: Instead of continuous real-time replication, changes are batched and periodically propagated across nodes. This can be accomplished through mechanisms such as:
- Logical Replication: Using logical replication to capture and propagate changes using replication slots.
- Batch Processing: Collecting transaction logs and transmitting them at scheduled intervals.
- Conflict Resolution: Offline replication inherently risks conflicts, as nodes make changes independently. Conflict resolution strategies could involve:
- Priority-Based Overrides: Designating certain nodes as having higher consistency priority.
- Custom Conflict Resolution Policies: Implementing logic to determine the winning transaction (e.g., timestamp-based resolution).
Key Components
- Replication Triggers: These triggers allow capturing changes locally and preparing them for batch synchronization.
- Replication Scheduling: A scheduler that determines when synchronization processes are executed.
- Conflict Resolution Logic: The business logic to handle potential data conflicts.
Advantages and Use Cases
Advantages
- Reduced Infrastructure Costs: Enables multi-site deployments without necessitating full-time connectivity, reducing bandwidth usage and related costs.
- Flexibility and Fault Tolerance: Localize database functionality even when disconnected from other sites, offering fault tolerance.
- Simplified Deployment: Mitigates some complexities of real-time multi-master setups by ensuring consistency asynchronously.
Suitable Use Cases
- Remote Field Operations: Data collection systems across geographically distributed sites (e.g., oil rigs, field research, remote offices).
- Retail Environments: Multiple retail outlets can operate independently and synchronize with a central data repository periodically.
- Multi-Region Web Applications: Applications optimizing for regional database writes with eventual consistency across regions.
Limitations and Challenges
While offering benefits, offline limited multi-master replication schemes present several limitations:
- Eventual Consistency: Guarantees all nodes reach the same state eventually, but they may not reflect real-time changes, impacting time-sensitive applications.
- Conflict Management: Requires robust conflict resolution strategies that can still lead to data anomalies if not well-designed.
- Additional Complexity: Startup and maintenance can be more complex compared to single-master setups, requiring thoughtful planning and configuration.
Comparative Summary
| Feature | Offline Limited Multi-Master | Fully Real-Time Multi-Master |
| Connectivity Requirement | Intermittent Ideal for remote or less connected contexts | Constant Requires persistent connectivity |
| Consistency Model | Eventual Consistency Periodic sync | Strong Consistency Real-time sync required |
| Infrastructure Cost | Lower Reduced bandwidth & infrastructure costs | Higher Needs investment in continuous sync mechanisms |
| Conflict Resolution | Necessary Manual or automated conflict handling | Critical Usually built-in or third-party tools |
| Use Cases | Retail chains, Remote data collection systems | Real-time collaborations, Banking systems |
Concluding Remarks
Offline limited multi-master replication in PostgreSQL presents a viable approach to balancing the need for distributed write capabilities against the overhead and complexity associated with real-time multi-master setups. While it may not fit every application, it offers compelling benefits for specific use cases where eventual consistency is acceptable. Like any architectural choice, it requires careful consideration of application needs, anticipated data access patterns, and network reliability to ensure optimal deployment.
Related reading
- Old I/O thread per client model or NIO reactor pattern?
- One kafka consumer for multiple topics vs one consumer for each topic/partition
- One Lambda Function OR Multiple Lambda Functions
- Optimal number of partition for kafka topic on 5 brokers with replication factor=3 in 1 cluster
- Offset/limit to page/size conversion
- On duplicate key ignore?
- Oracle DB Intranet -DMZ Data Replication through a unidirectional Firewall
- Oracle replication data using Apache kafka

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.