Skip to main content
ANNOUNCEMENTMeet MariaDB Enterprise Platform 2027. Read more.

Menu

WEBINAR

Built for the Agentic Era: Introducing MariaDB Enterprise Platform 2027

Register now

Product

Multi-Region Active-Active with MariaDB: A Conflict Resolution Use Case

By Aijaz Fatima

17 min read
Share

Key takeaways

  • Write at Every Site: Use CD&R to handle conflicts in multi-writer deployments using standard asynchronous or semi-synchronous replication.
  • Detect Five Conflict Types: MariaDB detects conflicting inserts, updates, and deletes across sites and runs the SQL trigger you define for each conflict type.
  • Resolve It Your Way: Keep the winning row, such as the later write, merge changes field by field, add up counters, skip the incoming row event, or stop replication for investigation.
  • Keep Every Node in Agreement: Design rules that produce the same result regardless of arrival order. In our six four-way update races, all four nodes picked the same winner.
  • Recover Without Intervention: Sites can continue accepting local writes while disconnected; CD&R handles supported conflicts when replication resumes. In our test, all 12 channels were running again in about four seconds without operator intervention.
CREATE TRIGGER lww_upd_upd
  FOR CONFLICT UPDATE_UPDATE ON subscriber
  FOR EACH ROW
BEGIN
  -- Skip an incoming version identical to the local row.
  IF NEW.status <=> OLD.status
     AND NEW.location <=> OLD.location
     AND NEW.`server ID` <=> OLD.`server ID`
     AND NEW.`timestamp` <=> OLD.`timestamp` THEN
    SIGNAL SQLSTATE '02TRG';
  END IF;

  -- Keep the local row if its timestamp is later,
  -- or its server ID is higher when timestamps match.
  IF OLD.`timestamp` > NEW.`timestamp`
     OR (OLD.`timestamp` = NEW.`timestamp`
         AND OLD.`server ID` > NEW.`server ID`) THEN
    SIGNAL SQLSTATE '02TRG';
  END IF;

  -- Otherwise, apply the incoming row.
END
CREATE TRIGGER add_up
  FOR CONFLICT UPDATE_UPDATE ON usage_counter
  FOR EACH ROW
  SET NEW.counter = OLD.counter + (NEW.counter - ORG.counter);
SELECT Last_SQL_Errno, Last_SQL_Error 
FROM information_schema.SLAVE_STATUS;
SHOW GLOBAL STATUS LIKE 'Executed_triggers';

MariaDB CD&R enables multi-site active-active database deployments using standard asynchronous or semi-synchronous replication to automatically detect replication conflicts and resolve them via custom SQL triggers without manual intervention. It is available in MariaDB Enterprise Server 12.3 and later.

CD&R works with standard asynchronous and semi-synchronous MariaDB replication, in primary–replica, multi-source, bidirectional, ring, mesh, and star topologies. You can write at every site without waiting on the others, and you define the rules that settle conflicts with no extra cost of network overhead. Raft Cluster is a single-writer system: all writes go through one leader. That makes commits faster, especially across regions, but it doesn’t give you multi-write capability. Galera Cluster gives you multi-write, so you can write to any node, but because it’s synchronous, every commit waits on all the nodes. Neither needs CD&R: Galera uses certification to detect conflicting transactions, and Raft’s single leader means there are no write conflicts.

No. It retains the winning row and discards the competing version. Use a merge policy when you need to preserve contributions from both writes.

No. It retains the winning row and discards the competing version. Use a merge policy when you need to preserve contributions from both writes.

No. The policy must also produce the same result regardless of which node receives the change or the order updates arrive.

You can deliberately stop the replication SQL thread for investigation. An unhandled trigger error can also stop replication.

With an appropriately configured asynchronous multi-writer architecture, sites can continue accepting local writes. After replication reconnects, CD&R handles supported conflicts according to your rules.

Check replication progress, then compare records or checksums at a consistent point. Running replication threads alone does not prove data agreement.