Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Microservice Architecuture with Event Sourcing @ Sydney JVM Meetup

277 views

Published on

Event-streaming architecture for modern data-driven services

Published in: Technology
  • Be the first to comment

Microservice Architecuture with Event Sourcing @ Sydney JVM Meetup

  1. 1. Microservice Architecture with Event Sourcing Shahid Zaman Boris Kravtsov
  2. 2. Microservice architecture is a method of developing software applications as a suite of independently deployable, small, modular services in which each service runs a unique process and communicates through a well-defined, lightweight mechanism to serve a business goal Microservice Architecture
  3. 3. ▪ Build and ship code faster and cheaper ▪ Reduction of complexity? ▪ Horizontal vs vertical scaling ▪ Web scale ▪ Breaking down the monolith ▪ Organisational changes Why Microservices?
  4. 4. ▪ REST with light weight JSON vs WS-* spec ▪ Global canonical model vs bounded context per service ▪ Shared database with tight coupling vs loosely coupled database per service SOA vs Microservices
  5. 5. ▪ Smaller services where code can fit in one developer’s head ▪ Independently deployed and scaled ▪ Improved fault isolation ▪ Polyglot technical architecture - ‘best’ tool for the job ▪ Fail fast - easily experiment Benefits of Microservices
  6. 6. Drawbacks of Microservices ▪ Additional complexity in distributed system ▪ Partial failures ▪ Polyglot persistence and distributed transactions? ▪ Testing is hard ▪ Operational complexity ▪ Requires CI/CD ▪ Changes in business processes and organisational structure
  7. 7. Domain Driven Design - DDD ▪ Place the project's primary focus on the core domain and domain logic ▪ Base complex designs on a model of the domain
  8. 8. Bounded Context
  9. 9. REST with CRUD ▪ Antipattern ▪ Database as a service thinking ▪ Exposing internal database structure instead of a well thought out contract ▪ Simple client-server architecture
  10. 10. Event Sourcing ▪ Storing state vs storing a sequence of store changing events ▪ State is recorded as a complete series of events from actions taken within a domain ▪ Replaying of events to restore state ▪ In contrast with CRUD where only current state of an entity is stored ▪ Append only / immutable store ▪ Event history is replayed to retrieve the current state of an entity ▪ Snapshots can help in situations where there is too much history
  11. 11. ▪ Solves data concurrency issues ▪ Solves Object-relational impedance mismatch problem ▪ Retains state across time. Temporal queries are possible ▪ Reduces complexity in testing ▪ Allows for multiple views of data Benefits of Event Sourcing
  12. 12. Managing complexity - testing
  13. 13. ▪ New apps only - requires a rewrite ▪ More complex to implement and requires skilled developers ▪ Querying event store is challenging - state needs to be reconstructed ▪ Its not a top level architecture and should be applied selectively Drawbacks of Event Sourcing
  14. 14. ▪ Stands for: Command Query Responsibility Segregation ▪ Inspired by Event Sourcing, but only a first stepping stone and not an architecture ▪ Write and Read are separate CQRS
  15. 15. ▪ Query and write scalability ▪ Business focus ▪ Reduction of complexity ▪ Solves ORIM problem Benefits of CQRS
  16. 16. ▪ Added complexity ▪ Weird Drawbacks of CQRS
  17. 17. GemFire (Apache Geode) GemFire is a distributed, in-memory database with strong data consistency, built to support transactional applications with low latency and high concurrency needs
  18. 18. GemFire ServerGemFire Server GemFire with CQRS GemFire Server Partitioned Data Partitioned Data Client query Partitioned Query Data write Partitioned Query Data Partitioned Query Data automatic cache invalidationcontinuous query
  19. 19. ▪ What is the scenario again? ▪ Microservice architecture ▪ Event sourced data model ▪ CQRS patterned data access Where does Spring fit in this scenario? • Spring Boot • Spring Cloud/Netflix projects • Spring Cloud Stream • Project Reactor https://github.com/benwilcock/microservice-sampler
  20. 20. Spring Cloud/Netflix projects • Spring Cloud Config provides server and client-side support for externalised configuration in a distributed system. • Spring Cloud Netflix - Eureka for service discovery • Spring Cloud Netflix - Zuul for Gateway service • Spring Cloud Netflix - Ribbon for software load balancing https://github.com/benwilcock/microservice-sampler
  21. 21. ▪ Spring Cloud Stream is a framework for building message-driven microservices. ▪ Built on top of Spring boot. ▪ Based on the model of Spring Integration @SpringBootApplication @EnableBinding(Source.class) public class StreamdemoApplication { public static void main(String[] args) { SpringApplication.run(StreamdemoApplication.class, args); } @Bean @InboundChannelAdapter(value = Source.OUTPUT) public MessageSource<String> timerMessageSource() { return () -> new GenericMessage<>(new SimpleDateFormat().format(new Date())); } } Spring Cloud Stream
  22. 22. ▪ Lots of microservices and coordination benefits from reactive programming model ▪ Avoid latency and increase better throughput ▪ Project reactor is an implementation of Reactive Streams spec for JVM ▪ Process unbounded number of elements in sequence ▪ Asynchronously call and pass elements between components ▪ With backpressure implementation Project Reactor
  23. 23. start.spring.io

×