徐少杰:Event sourcing & CQRS

赖采蓝

2017/11/14 发布于 技术 分类

在过去的一年多以来,可能被讨论最多的就是reactive programming, message driven programming, distributed persistence, event sourcing, CQRS和DDD了。如果有那么一个框架,天生就具备了上述所提到的一系列特性,而其核心是由一系列优秀成熟的技术框架所组成,有Scala社区全全支持,你是否会考虑使用他呢?是的,它就是微服务领域框架的后起之秀,Lagom,一个基于Play,Akka,Kafka,Cassandra和ConductR的微服务框架。如果你热衷于Spring Cloud,因为它可以让你轻松搭建微服务,那么你会发现Lagom可以让你轻松搭建一个基于云架构的微服务系统。

文字内容
1. SACC2017
2. Event architecting Sa coloSuudArbCcasCiend2mg0ic1r&7o-serCvicQe syRsteSm
3. About me 017• Oracle Certified Expert J2EE CC2• Software Engineer SA• Software Architect
4. Agenda • Event Driven Architecture 17• Event Sourcing C20• CQRS SAC• Lagom in a nut shell • Demo • Q&A
5. SACC2017
6. What we need? • Availability • • • SRPceearsflioalibreminlicatynyceSACC2017 • Innovation
7. Monolith VS Micro-Service SACC2017
8. Inter-service Communication SACC2017
9. SACC2017
10. REST API Call SACC2017
11. Micro service spaghetti SACC2017
12. Reactive Manifesto SACC2017
13. Event Driven Architecture 17• Production, detection, consumption and reaction to events C20• Services publish events when there is a state change SAC• Other services subscribe events to obtain state changes • To achieve a loosely coupled distributed system
14. Event Driven Architecture SACC2017
17. Event Sourcing a core concept from DDD SACC2017
18. Active current record SACC2017
19. Actual event happened SACC2017 no update, no delete only append
20. Event sourcing like application • • bank git statement SACC2017 • database transaction log
21. Events 017• History, can never be changed C2• Immutable, we love immutability SAC• Generate corrective events • Allow asynchronous communication
22. Event Sourcing • Define the aggregates, or domain entities 17• Identify domain events 20• Capture all changes (commands) and convert them to domain events SACC• Examples: • Bank Account : accountCreated; depositPerformed; withdrawalPerformed • Order : orderCreated; orderUpdated; orderPaid; orderShipped
25. Benefits • 100% accurate audit logging • easy debugging 017• real time stream processing C2• writing is blazing fast, since it is SACappend only • no impedance mismatch • building a forward-compatible application architecture 
26. But! SACC2017• What’s the total amount of all transaction from this month? • Search all products with the brand Gucci and cost less than 1000 euro for female?
27. Oh dear ! SACC2017
28. CQRS SACC2017
29. CQRS C Q R : : : crqeousmepromyna-s>nibdriel-Sia>tdyAwCritCe/a2p0pe1n7d S : segregation
30. Traditional approach SACC2017 https://martinfowler.com/bliki/CQRS.html
33. Lagom SACC2017
34. Lagom 017• From Lightbend, a Scala company CC2• Opinionated Microservices Framework SA• Early adoption phase • Aims for micro-service system • Based on actor model
35. Lagom Technology Stack SACC2017
36. API Overview • Service API Asynchronous streaming between services 7Synchronous request-response calls 01• Persistence API C2Event-sourced persistent, CQRS read-side support SACPersistent entities managed automatically across a cluster of nodes Persistent entity is an actor Cassandra • Message Broker API Publish-subscribe model Share data via topics Push and pull, back pressure
37. Actor Model SACC2017
38. Let’s Demo SACC2017
39. Service API Declaration of Service Descriptors SACC2017
40. Service API Implementation of HelloService SACC2017
41. Persistence API CreateUser Command handler SACC2017
42. Persistence API AddFriend Command and GetUser Command Handler SACC2017
43. Persistence API CQRS Read Side Support Definition SACC2017
44. Persistence API View update based on FriendAdded event SACC2017
45. SACC2017