
Wed Sep 25 09:24:46 UTC 2024: ## Forget State Machines: Why Events Are The Future of Payments Engineering
**Payments Engineer Alvaro Duran argues against the use of state machines in payment systems, advocating for event-driven systems instead.**
Duran, who has built and maintained payment systems for almost a decade, draws a compelling analogy between the two approaches: Imagine chasing someone in the dark, shouting “Marco” and listening for their “Polo” response (state machine) versus following Google Maps directions (event-driven).
While both approaches achieve the goal, the event-driven method offers crucial benefits, especially in the context of payments.
**Here’s why Duran believes events are the way to go:**
* **Replayability:** Events allow for complete reconstruction of past transactions, crucial for debugging and resolving payment disputes. State machines lack this capability, making it difficult to prove the legitimacy of a payment.
* **Scalability:** Event-driven systems are inherently more scalable than state machines, which struggle to handle the high volume of transactions typical in today’s payment systems.
* **Domain Knowledge:** Events encourage a deeper understanding of the payment process, providing clients with more context than state machines, which simply expose the current status.
Duran emphasizes the importance of common libraries to facilitate consistent state reconstruction from events, simplifying integration and reducing errors. He argues that existing payment APIs based on state machines are often complex and error-prone, leading to cumbersome integration processes.
**Events offer a clear advantage:**
* **Individual Clarity, Collective Power:** Events are simple and straightforward individually but provide a comprehensive narrative when viewed collectively, allowing for easier debugging, understanding, and reporting.
* **Flexible Architecture:** Events can be used in both pull-based and push-based systems, offering greater flexibility and scalability.
**Duran concludes by challenging payments engineers to embrace events and move away from state machines.** He believes that this shift will lead to more transparent, scalable, and reliable payment systems.
**”It’s a matter of giving clients what they need, rather than making sure they stay inside your walled gardens,” writes Duran, emphasizing the importance of open communication and transparency in the payments landscape.**
**This insightful article is part of The Payments Engineer Playbook, a blog dedicated to exploring the technical intricacies of money transfer systems.** You can subscribe to receive new posts and support Duran’s work.