Functional Event-Driven Architecture
Functional Event-Driven Architecture
Powered by Scala 3
About the Book
Explore the event-driven architecture (EDA) in a purely functional way. Learn to design and develop distributed systems that scale. Identify common design patterns in such systems.
In the same spirit of Practical FP in Scala, we will develop a distributed system written in Scala 3 that meets the requirements of a modern software architecture capable of processing billions of events per day at scale powered by Apache Pulsar and Fs2 streams.
The system also includes a Web Sockets service powered by Http4s, and two Web applications (one written in Elm; another in Scala.js), just for fun!
Although the application picks a particular design and implementation, the concepts should easily translate to other designs in the same space that can be built on top of Apache Kafka, Rabbit MQ, or other message brokers.
Additionally, essential reading material is recommended for those who wish to dive deeper into topics such as Distributed Systems, Streaming Systems, Event-Driven Applications, and Observability.
Have a look at the distributed system that supplements this book: https://github.com/gvolpe/trading
Bundles that include this book
Table of Contents
- Preface
-
Acknowledgments
- People
- Software
- Fonts
-
Prerequisites
- Reading material
-
How to read this book
- Conventions used in this book
- Part I: Concepts
-
1. Event-driven architecture
-
1.1 Introduction
- 1.1.1 What problems does it solve?
- 1.1.2 When to use it? When not?
-
1.2 Microservices architecture
- 1.2.1 Scalability
- 1.2.2 Fault tolerance
- 1.2.3 Observability
- 1.2.4 Versatility
-
1.3 CQRS/ES
- 1.3.1 Commands
- 1.3.2 Queries
- 1.3.3 Reads & writes
- 1.3.4 When to use it? When not?
- 1.3.5 Frameworks
- 1.4 Summary
-
1.1 Introduction
-
2. Distributed systems
-
2.1 Overview
- 2.1.1 Identifying points of failure
- 2.1.2 Consistency vs availability
-
2.2 Idempotence
- 2.2.1 De-duplication
-
2.3 Atomicity
- 2.3.1 Distributed transactions
- 2.3.2 Change data capture
- 2.3.3 Distributed locks
- 2.4 Summary
-
2.1 Overview
-
3. Stateless vs. Stateful
-
3.1 Stateless services, stateful brokers
- 3.1.1 Stateful services
- 3.1.2 Application clustering
-
3.2 Message-driven architecture
- 3.2.1 Delivery guarantees
- 3.2.2 Apache Kafka
- 3.2.3 Apache Pulsar
- 3.2.4 What should I use?
-
3.3 State snapshots
- 3.3.1 Retention policy
-
3.4 Schema evolution
- 3.4.1 Schema compatibility
- 3.4.2 Versioning strategies
- 3.4.3 Schema registry
- 3.5 Summary
-
3.1 Stateless services, stateful brokers
- Part II: Coding
-
4. Functional programming in Scala 3
-
4.1 Domain modeling
- 4.1.1 Typeclass derivation
- 4.1.2 Newtypes
- 4.1.3 Refinement types
- 4.1.3 Orphan instances
- 4.2 Typeclasses
- 4.3 HTTP routes
- 4.4 Effectful context
- 4.5 Dependent types
- 4.6 Summary
-
4.1 Domain modeling
-
5. Effectful streams
- 5.1 Finite state machines
- 5.2 Resources and lifecycle
-
5.3 Data pipelines
- 5.3.1 Real-time
- 5.3.2 Batching
- 5.3.3 Analytics
- 5.3.4 Data source
-
5.4 Producer-consumer
- 5.4.1 In-memory via Queue
- 5.4.2 Distributed via Apache Pulsar
- 5.4.3 Distributed via Apache Kafka
- 5.5 Summary
- Part III: System
-
6. Trading system (core services)
-
6.1 Business requirements
- 6.1.1 Overview
- 6.1.2 Domain modeling
- 6.1.3 Shared modules
-
6.2 Processor
- 6.2.1 Commands
- 6.2.2 Events
- 6.2.3 Command-event relationship
- 6.2.4 Entry point
- 6.2.5 FSM
- 6.2.6 Deep analysis
- 6.2.7 Scalability
- 6.2.8 Run
-
6.3 Alerts
- 6.3.1 Datatypes
- 6.3.2 Event-alert relationship
- 6.3.3 FSM
- 6.3.4 Entry point
- 6.3.5 Scalability
- 6.3.6 Run
-
6.4 Web Sockets
- 6.4.1 Datatypes
- 6.4.2 HTTP routes
- 6.4.3 Events handler
- 6.4.4 Unit tests
- 6.4.5 Entry point
- 6.4.6 Run
- 6.4.7 Scalability
- 6.4.8 Addendum
- 6.5 Summary
-
6.1 Business requirements
-
7. Trading system (alt services)
-
7.1 Snapshots
- 7.1.1 Scalability
- 7.1.2 Entry point
- 7.1.3 FSM
- 7.1.4 Run
-
7.2 Forecasts
- 7.2.1 Commands
- 7.2.2 Events
- 7.2.3 Command-event relationship
- 7.2.4 Engine
- 7.2.5 SQL store
- 7.2.6 Scalability
- 7.2.7 Entry point
- 7.2.8 Run
-
7.3 Feed
- 7.3.1 Generators
- 7.3.2 Run
-
7.4 Integration tests
- 7.4.1 Redis suite
- 7.4.2 SQL suite
- 7.5 Summary
-
7.1 Snapshots
-
8. Trading system (observability)
-
8.1 Tracing
- 8.1.1 Distributed
- 8.1.2 Centralized
-
8.2 Build & run
- 8.2.1 Docker compose
- 8.2.2 Continuous integration
- 8.2.3 Smoke tests
-
8.3 Monitoring
- 8.3.1 Prometheus
- 8.3.2 Grafana
-
8.4 Deployment
- 8.4.1 K8s cluster
- 8.4.2 Pods management
- 8.5 Summary
-
8.1 Tracing
-
9. Bonus: Web App
- 9.1 Entry point
- 9.2 Datatypes
- 9.3 View
- 9.4 Subscriptions
- 9.5 Updates
- 9.6 Build & run
- 9.7 Summary
Other books by this author
The Leanpub 60 Day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.
You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!
So, there's no reason not to click the Add to Cart button, is there?
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earnedover $13 millionwriting, publishing and selling on Leanpub.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them