lagom at hybris reactive software munich meetup, april 13, 2016
TRANSCRIPT
![Page 1: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/1.jpg)
Lutz Huehnken@lutzhuehnken
Reactive Microservices
![Page 2: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/2.jpg)
Overview
![Page 3: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/3.jpg)
Overview
![Page 4: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/4.jpg)
What are those opinions?• Use context bounds as boundaries for services! (Domain
Driven Design) • The event log is the book of record! (Event Sourcing) • Separate the read and write sides! (CQRS) • Microservices, too, need to be elastic and resilient!
(Reactive) • Developer experience matters! (The Lagom development
setup)
![Page 5: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/5.jpg)
Size doesn’t matter (and why it’s called Lagom)
![Page 6: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/6.jpg)
All this hype about microservices makes me sad. And not about the concept, but about the name. As I wrote before, “micro” in “microservices” means absolutely nothing. What is worse, it confuses everybody. Again and again I see people focusing on “micro” and falling into nanoservices trap. Eugene Kalenkovich
![Page 7: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/7.jpg)
I call them Uniservices. Roland Kuhn
![Page 8: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/8.jpg)
The Self-contained System (SCS) approach is an architecture that focuses on a separation of the functionality into many independent systems, making the complete logical system a collaboration of many smaller software systems. http://scs-architecture.org
![Page 9: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/9.jpg)
Goodbye Microservices, Hello Right-sized Services. https://dzone.com/articles/goodbye-microservices-hello-right-sized-services
![Page 10: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/10.jpg)
Right-Sized Service doesn't really roll off the tongue, does it? Being Swedish I would prefer Lagomservice. Björn Antonsson (on a Lightbend internal mailing list)
![Page 11: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/11.jpg)
Lagom (pronounced [ˈlɑ̀ːɡɔm]) is a Swedish word meaning "just the right amount". The Lexin Swedish-English dictionary defines lagom as "enough, sufficient, adequate, just right". https://en.wikipedia.org/wiki/Lagom
![Page 12: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/12.jpg)
The ideas in Eric Evan’s Domain-Driven Design are very useful to us in finding sensible boundaries for our services. Sam Newman, „Building Microservices“, p. 38
![Page 13: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/13.jpg)
Event Sourcing and CQRS
![Page 14: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/14.jpg)
Lagom Persistence
Lagom Persistence
Event Sourcing
CQRSimplements leads to
Not covered: More Domain Driven Design, NoSQL Databases
![Page 15: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/15.jpg)
• We implement our aggregate roots as Persistent Entities
• Persistent Entities will receive commands • Triggered by a command, Persistent Entities
will change their state • Example: Add a friend, remove a friend
FriendService
Peter
Bob
Alice
Persistent Entities
![Page 16: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/16.jpg)
• Lagom allows you to scale out by forming a cluster of nodes
• Nodes can be added and removed dynamically
Node A
Lagom Cluster
Node B
Node C
Node Djoin
![Page 17: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/17.jpg)
• Lagom allows you to scale out by distributing your Persistent Entities in the cluster
Node A
Lagom Cluster
Node B
Node C
XBobAlice
Z
XY
PaulPeter
![Page 18: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/18.jpg)
• We have now moved from a CRUD approach to a Memory Image approach
• We keep all* our data in memory!
• See http://martinfowler.com/bliki/MemoryImage.html
(*) or a working set, actors can be passivated and activated as needed
Node A
Lagom Cluster
Node B
Node C
XBobAlice
Z
XY
PaulPeter
![Page 19: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/19.jpg)
• But how does our data survive a system crash?
• We log all the state changes!
Node A
Lagom Persistence
Node B
Node C
XBobAlice
Z
XY
PaulPeter
![Page 20: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/20.jpg)
Event Sourcing - storing deltas
• Every state change is materialized in an Event
• All events are stored in an Event Log • Current state is constructed by replaying
all events
![Page 21: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/21.jpg)
Event Sourcing - Storing Deltas
UserCreated (Alice)
Friend Added (Bob)
Friend Added (Peter)
Friend Removed(Bob)
![Page 22: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/22.jpg)
Traditional Way
User(Alice)
Friend (Peter)
Friend (Bob)
![Page 23: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/23.jpg)
Event Sourcing - benefits
• No object-relational impedance mismatch • Bullet-proof auditing and historical
tracing • Support future ways of looking at data • Performance and scalability • Testability
![Page 24: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/24.jpg)
![Page 25: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/25.jpg)
Persistent Entity
DataStore(e.g.CassandraCluster)
FriendService
YPeter
FriendService
XBobAlice FriendService
YXY
![Page 26: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/26.jpg)
Event Sourcing - Snapshots
1 2 100 101 102 103..
Snapshot
![Page 27: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/27.jpg)
Event Sourcing with Lagom Persistence
• Keep all data in memory! • Optional: Only working set, by using passivation/
activation
• Store all state changes as events • Replay all events of an actor to recreate it
• Optional: Start from snapshot
• Scale out with Lagom Cluster and scalable data store
![Page 28: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/28.jpg)
Read-Side
UserCreated(Alice)
FriendAdded(Bob)
FriendAdded(Peter)
Alice
Bob
Peter
Alice
Bob
X
Y
![Page 29: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/29.jpg)
Read-Side
UserCreated(Alice)
FriendAdded(Bob)
FriendAdded(Peter)
FOLLOWERSuserid followedby
BobAliceBobXBobYPeterAlice
![Page 30: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/30.jpg)
Read side is derived from event log
• Events forwarded to read side to build different representations
• ElasticSearch • SQL, de-normalized • Stream Processor / Analytics • BI • OLAP • …
![Page 31: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/31.jpg)
Read side cont’d
• Read side can be discarded and re-created.
• The „book of record“ is the event log. • Read side can be scaled out by creating
copies - it’s read only.
• Btw, you can get a status for an identified entity on the write side, too.
![Page 32: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/32.jpg)
![Page 33: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/33.jpg)
Consistency
FOLLOWERSuserid followedby
BobAliceBobXBobYPeterAlice
DataStore(e.g.CassandraCluster)
Alice1 - Actor
2 - Journal / Event Store
3 - Read Side
![Page 34: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/34.jpg)
Consistency
Alice1 - Actor
• A Persistent Entities defines an Aggregate Root
• Aggregate Root is the Transactional Boundary
• Strong consistency within an Aggregate Root
• Commands are executed sequentially on the latest state
• No limit to scalability
![Page 35: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/35.jpg)
Consistency
DataStore(e.g.CassandraCluster)
2 - Journal / Event Store
• Depending on implementation / configuration
• Popular choice: Cassandra • „Tunable Consistency“ • Proper use of quorum ensures
consistency
![Page 36: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/36.jpg)
Consistency
FOLLOWERSuserid followedby
BobAliceBobXBobYPeterAlice
3 - Read Side
• Will not be updated immediately, but deferred
• Not much different from queries in interactive applications
![Page 37: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/37.jpg)
Event Sourcing with Lagom Persistence revisited
• Keep all data in memory! • Store all state changes as events • Replay all events of an actor to recreate it • Strong consistency for Actor (aggregate)
and Journal • Eventual Consistency for Read Side
![Page 38: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/38.jpg)
If you really, really don’t want to use Event Sourcing
• Don’t use Lagom Persistence • You can use whatever data store you like • Beware of blocking APIs (JDBC..) • For Cassandra, you can use the
CassandraSession from the Persistence module
![Page 39: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/39.jpg)
Reactive
![Page 40: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/40.jpg)
Reactive
![Page 41: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/41.jpg)
• Asynchronous I/O
• Asynchronous communication as first class
• WebSocket support
• Reactive Streams support
• Distributed by default
• Built-on Akka Clustering, Sharding, Persistence
Reactive
![Page 42: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/42.jpg)
![Page 43: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/43.jpg)
Developer Experience
![Page 44: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/44.jpg)
• Run all microservices at once
• Embedded Cassandra DB
• Intra-service communication via service locator
• Hot reloading
Development tooling
![Page 45: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/45.jpg)
• Getting started: lightbend.com/lagom
• Examples: lightbend.com/activator/templates
• Contribute: https://github.com/lagom
• Communicate:
• https://groups.google.com/forum/#!forum/lagom-framework
• https://gitter.im/lagom/lagom
• Lightbend Proof of Concept Program: lightbend.com/company/contact
Try it out
![Page 46: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/46.jpg)
Read this book
https://www.lightbend.com/reactive-microservices-architecture
(free, registration required)
![Page 47: Lagom at hybris Reactive Software Munich Meetup, April 13, 2016](https://reader035.vdocument.in/reader035/viewer/2022062823/587701a91a28ab890e8b484f/html5/thumbnails/47.jpg)