# Event Sourcing Scaling - Pay Less, Do More

- Speaker: [Michael Feinstein](/wiki/speakers/michael-feinstein.md)
- Event: [Reversim Summit 2018](/wiki/years/2018.md)
- Video: https://www.youtube.com/watch?v=p0oe2BPl6zw
- Transcript: [/transcripts/2018/31-p0oe2BPl6zw.md](/transcripts/2018/31-p0oe2BPl6zw.md)
- Language: English · Type: talk · Level: intermediate
- Topics: [Scalability](/wiki/topics/scalability.md), [Cloud Computing](/wiki/topics/cloud.md), [Distributed Systems](/wiki/topics/distributed-systems.md), [Databases](/wiki/topics/databases.md)

> Written by an LLM from machine transcripts. It can contain errors. Check the transcript before you quote it.

## Summary

The speaker shares how an infrastructure team improved the efficiency, performance, and cost-effectiveness of an event-driven microservices architecture under extreme load. By replacing standard queue-depth metrics with a combined metric of queued and in-progress messages, and by measuring and scaling more frequently, the team eliminated latency peaks. They also introduced worker locking during message processing to prevent dead-letter loops and maintained a cloud provider fallback for high availability. Ultimately, the audience learns practical strategies for optimizing cloud costs and auto-scaling reliability in event-sourcing systems.

## Key points

- [0:12](https://www.youtube.com/watch?v=p0oe2BPl6zw&t=12s) The infrastructure team balances simplicity, customer SLAs, and financial costs across a microservices architecture.
- [5:17](https://www.youtube.com/watch?v=p0oe2BPl6zw&t=317s) The system relies on an asynchronous, event-based backend where services communicate entirely through published messages and queues.
- [11:30](https://www.youtube.com/watch?v=p0oe2BPl6zw&t=690s) Standard cloud provider auto-scaling based solely on queue depth is reactive and leads to delayed responses and wasted compute instances.
- [13:33](https://www.youtube.com/watch?v=p0oe2BPl6zw&t=813s) A better scaling metric combines the number of queued messages with messages currently in progress plus idle compute spares.
- [18:37](https://www.youtube.com/watch?v=p0oe2BPl6zw&t=1117s) Scaling in workers randomly can terminate instances that are actively processing messages, returning them to the queue and artificially inflating demand.
- [19:37](https://www.youtube.com/watch?v=p0oe2BPl6zw&t=1177s) Implementing a worker-locking mechanism ensures that only idle instances are terminated during scale-in operations.
- [24:39](https://www.youtube.com/watch?v=p0oe2BPl6zw&t=1479s) Retaining the cloud provider's native auto-scaling mechanism as a fallback ensures system resilience if the custom scaling service fails.

## Takeaways

- Base auto-scaling decisions on a combination of queue depth and active in-progress tasks rather than queue depth alone.
- Lock workers that are actively processing messages to prevent them from being terminated and re-queuing unfinished work.
- Maintain a simpler out-of-the-box cloud scaling mechanism as a reliable fallback for your custom scaling logic.

## Questions this talk answers

- How can you avoid the latency and cost penalties of reactive queue-based auto-scaling?
- What causes phantom demand spikes when scaling in an event-driven worker pool?
- How do you build a safe fallback mechanism when implementing custom auto-scaling logic?

## Technologies

AWS Lambda, EC2, PagerDuty

## Tags

auto scaling, cloud costs, distributed systems, event sourcing, infrastructure, microservices, monitoring
