Best-Effort One-Phase Commit and the Dual-Write Problem

Distributed applications frequently need to coordinate operations across multiple transactional resources. A service might update a database and acknowledge a message, or persist a record and invoke a remote API. The challenge is that these operations are independent. A successful database commit does not guarantee that a message acknowledgement or remote API call will succeed. One commonly adopted strategy is best-effort one-phase commit (1PC). Rather than introducing a distributed transaction coordinator, it relies on careful transaction ordering and idempotent processing to reduce the risk of inconsistent outcomes. ...

May 15, 2024 · 12 min · Kai Niemi

Cluster Singleton Scheduling with Spring Boot and ShedLock

Spring Boot makes it easy to schedule recurring tasks using the @Scheduled annotation. This works well for a single application instance, but what happens when the application is deployed across multiple servers or regions? Each instance runs its own scheduler, meaning the same task may execute concurrently on several instances. For some workloads, this is harmless. For others, such as importing data, publishing notifications, or performing periodic cleanup, concurrent execution can cause duplicate processing or conflicting updates. ...

October 19, 2022 · 9 min · Kai Niemi

Designing Idempotent REST APIs: Stateless Preconditions and Idempotency Keys

How do you safely retry a POST request when the outcome is unknown? A comparison of stateless preconditions and idempotency keys, using funds transfers as an example.

October 19, 2022 · 15 min · Kai Niemi

Multi-Active Systems and Multi-Region Architectures

Several business drivers can justify adopting a multi-region deployment strategy: Business continuity: Maintain service availability during data centre or regional disruptions. Customer experience: Serve customers worldwide with predictable, low latency. Scalability: Adapt capacity to different markets and changing traffic volumes. Regulatory compliance: Address data residency, operational resilience, and concentration risk requirements. None of this is free. A multi-region deployment typically costs more than a single-region one, and that cost has to be weighed against the availability and performance it buys. ...

October 19, 2022 · 10 min · Kai Niemi