While there are many who claim adopting a microservices architecture will yield several benefits, it usually takes more work for those benefits to be fully experienced. This is especially true with monolith-to-microservices migrations, where developers still think in an synchronous REST mindset. In this talk, we'll discuss what is required to move to async services and how adopting an event-driven architecture can promote self-healing, rapid prototyping, and graceful degradation and tradeoffs associated with this kind of move.
5. Typical Monolith:
function onComment (c) {
var text = parser.normalize(c)
db.saveComment(text)
emailer.sendThanks()
}
Music player
Video hosting
Comments
Database
Emailer
Text Parser
the-best-music.com
13. Reactive Stack
// Legacy
function onComment (c) {
bus.emit(‘comment.received’, c)
}
// Emailer
function onCommentReceived (c) {
sendThanks(c)
}
// Database
function onCommentNormalized (text) {
saveComment(text)
}
// Snapchat
function onCommentReceived (c) {
sendSelfie()
}
// Parser
function onCommentReceived (c) {
var text = normalize(c)
bus.emit(‘comment.normalized, text)
}
14. Wins
● Services are truly decoupled
● Lower risk of new changes
● Graceful degradation
● Self-healing
● Promotes independent teams
15. Woes
● Message bus is now a SPOF
○ Should be highly available
○ Should persist messages
● Debugging difficulty
○ Log messages with ids, publisher, and consumer
○ Maintain up-to-date documentation of events
● Eventual Consistency
○ Event consumers should be idempotent
○ Message bus should guarantee at least once delivery
16. In practice
We have been using this in production and it has helped us tremendously!
● New features with less risk
● Less complexity and code
● Helped with unstable endpoints
● Great new hire tasks