- Microservices: Improving the autonomy of our teams with Event-Driven Architecture discusses migrating from a monolithic architecture to microservices and event-driven architecture.
- It explores how this impacts development team autonomy and scalability. It also analyzes a migration plan from monolith to service-based architecture.
- The document outlines stages including starting with a monolith, then moving to microliths which improved codebase scaling but led to infrastructure scaling issues. It describes how event-driven architecture can further decouple services.
3. Goals
🧠 Explore the implications of an Event-Driven Architecture in terms of:
👥 Development teams management and autonomy
🚀 Scalability
🗺 Analyze a migration plan from a monolith to a service based architecture
Intro
7. 🗿 Stage 1: The Monolith
Problem: The Domino Effect
8. Stage 1: The Monolith
THE MONOLITH
GET /users/x PUT /videos/x
DB
{
"id": “some-uuid",
"name": “Codelyber",
"total_videos_created": 1
}
🧠
9. &
🙋
THE MONOLITH
🧠
Stage 1: The Monolith
GET /users/x PUT /videos/x
GET /courses/x
GET /paths/x
GET /videos/x/comments
GET /videos/x/likes
💩
💩
💩💩
💩💩
💩
💩
💩
☀☀
☀☀
💩
💩
💩💩💩💩 💩 💩
💩
💩
💩
💩
💩
💩
DB
💧
10. THE MONOLITH
🧠
Stage 1: The Monolith
GET /users/x PUT /videos/x
GET /courses/x
GET /paths/x
GET /videos/x/comments
GET /videos/x/likes
💩
💩
💩💩
💩💩
💩
💩
💩
☀☀
☀☀
💩
💩
💩💩💩💩 💩 💩
💩
💩
💩
💩
💩
💩
DB
x1000
🔥
11. Recap Stage 1: The Monolith
👥 Development teams management and autonomy
👎 Same codebase
🚀 Scalability
👎 Development scaling issues
👎 Application scaling issues
👎 Infrastructure scaling issues
Stage 1: The Monolith
13. Haters advisory
🎯 Assume we’ve actual needs to implement a [micro]services architecture:
. Multiple development teams
🌈 Different needs that require different programming languages
📊 Different scaling needs for each service
Stage 1: The Monolith
14. 🗿 Stage 2: The Microliths 🗿
Problem: Domino Effect
15. Stage 1: The Monolith
THE MONOLITH
GET /users/x PUT /videos/x
DB
21. Changelog Stage 2: The Microliths
👥 Development teams management and autonomy
👍 Solved code base scaling issues
👎 Teams sharing the same DB schema
✋ Isolated DBA team: obfuscate priorities
🚀 Scalability
👍 Slightly better development scaling
👍 No application scaling issues
👎 Infrastructure scaling issues
Stage 2: The Microliths
38. USERS
DB
GET /users/x PUT /videos/xVIDEOS
DB
GET /videos?u_id=x
Stage 2.1: Coupled Microliths
🧠 🧠💩🕸
{
"id": “some-uuid",
"name": "Codelyber",
"total_videos_created": 0
}
👋☀
39. Changelog Stage 2.1: Coupled Microliths
👥 Development teams management and autonomy
👍 DB schema independence
👎 Inappropriate intimacy between teams => Use cases to develop &
maintain
👎 More work to do (SQL query vs. expose & consume HTTP endpoint)
🚀 Scalability
👍 No DB scaling issues
👎 Services coupling => Communication => Latency & Domino effect
Stage 2.1: Coupled Microliths
40. Changelog Stage 2.1: Coupled Microliths
👥 Development teams management and autonomy
👍 DB schema independence
👎 Inappropriate intimacy between teams => Use cases to develop &
maintain
👎 More work to do (SQL query vs. expose & consume HTTP endpoint)
🚀 Scalability
👍 No DB scaling issues
👎 Services coupling => Communication => Latency & Domino effect
Stage 2.1: Coupled Microliths
46. How do we apply this concept to our [micro]services?
Do you remember… SOLID!
From:
I
MySqlVideoRepositoryVideoCreator
VideoCreator
MySqlVideoRepository
VideoRepository
i
To:
D
A
I
49. USERS
DB
GET /users/x PUT /videos/xVIDEOS
DB
Subscribed to
video_created
e
Publishes
🧠 🧠☀
Stage 3: EDA
{
"id": “some-uuid",
"name": "Codelyber",
"total_videos_created": 1
}
| DB table fields |
|----------------------|
| id |
| name |
| total_videos_created |
50. USERS
DB
GET /users/x PUT /videos/xVIDEOS
DB
x1000
🔥🏖
🙂
🕶
video_created
e
Publishes
Subscribed to
🧠 🧠☀
Stage 3: EDA
51. Changelog Stage 3: Decoupling our teams
👥 Development teams management and autonomy
👍 Avoid inappropriate intimacy (develop & maintain use cases)
👍 OCP: Avoid having to modify current behaviour
☝ Learning curve (duplicated messages, order not guaranteed…)
🚀 Scalability
👍 No services coupling => No communication => Lower latencies & avoid
domino effect
👍 Replicate data => Shape it as needed by the team use cases
Stage 3: EDA
53. Base strategy
= PoC: Learn & define messaging architecture (RabbitMQ Simulator)
> Choose a little & not risky use case to develop in your new service
? Define your ACL: Domain events as interfaces/contracts
@ Migrate historical data from the legacy system to the new one (next slides)
A Start publishing events from the legacy system and consuming them from the
new one (next slide)
Microservices & Event-Driven Architecture
54. Migration plan fully based on domain events
= Migrate historical data:
= Legacy: Simulate the publication of events corresponding to historical data
based on the DB state saving them in the event store
> Copy all the events from the event store to a new queue X (history)
? New service: Consume all the events in the queue X
@ Remove temporary queue X
> Replicate new data changes:
= Legacy: Start publishing events in the new queue Y
> New service: Start consuming the events from queue Y
Microservices & Event-Driven Architecture
55. Migration plan speeding up initial data migration
= Legacy: Start publishing the needed events
> Legacy: Create a DB slave not exposing it to serve public requests
? Legacy: Stop DB replication in the new slave (this define The Moment X™)
@ Temporary script: Migrate historical data until The Moment X from the new
slave to the new service DB making the needed transformations
A New service: Start consuming the events published after The Moment X
C Remove the slave & temporary script created for the historical data migration
Microservices & Event-Driven Architecture
59. To take away
🧿 Decouple your teams thanks to EDA
🗺 SOLID principles can be applied at micro and macro-design levels
📃 Think about your Domain Events as you Domain interfaces/contracts
🕵 Inappropriate intimacy: Services exposing information just because of other
services need it. Simplify your services by limiting their APIs.
💡 Domain events as ACL. Useful while refactoring legacy systems.
Conclusions
61. & More info?
Mini-demo time!
🎥I Demo with PHP, Scala, and RabbitMQ (Spanish 🤟):
https://www.youtube.com/watch?v=1kaP39W80zQ
🐙🧣 https://github.com/CodelyTV/scala-http-api/
🐙🐘 https://github.com/CodelyTV/cqrs-ddd-php-example
62. 👉codely.tv/pro/cas-18 👈!codely.tv/pro/commit-18"
# 100 primeros => Primer mes a 19€
$ Tweet #commitCodelyTV => Sorteo 1 mes gratis
!codely.tv/pro/commit-18"
# 100 primeros => Primer mes a 19€
$ Tweet #commitCodelyTV => Sorteo 1 mes gratis
63. Related links
Performance Under Load
CodelyTV Pro Hexagonal Architecture course (Spanish)
CodelyTV Pro CQRS course (Spanish)
CodelyTV Pro Scala HTTP API course (Spanish)
Testing CQRS talk (Spanish)
We broke up with the monolith, and started dating #eventSourcing
Versioning in an Event Sourced System
RabbitMQ Simulator
A Series of Fortunate Events
The anatomy of Domain Event
& More info?
64. Wait!
Do we need [micro]services in
order to apply these concepts
at macro-design level?