microservice architecuture with event sourcing @ sydney jvm meetup

Post on 16-Apr-2017

90 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Microservice Architecture with Event Sourcing

Shahid Zaman Boris Kravtsov

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

▪ Build and ship code faster and cheaper

▪ Reduction of complexity?

▪ Horizontal vs vertical scaling

▪ Web scale

▪ Breaking down the monolith

▪ Organisational changes

Why Microservices?

▪ 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

▪ 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

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

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

Bounded Context

REST with CRUD

▪ Antipattern

▪ Database as a service thinking

▪ Exposing internal database structure instead of a well thought out contract

▪ Simple client-server architecture

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

▪ 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

Managing complexity - testing

▪ 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

▪ 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

▪ Query and write scalability

▪ Business focus

▪ Reduction of complexity

▪ Solves ORIM problem

Benefits of CQRS

▪ Added complexity

▪ Weird

Drawbacks of CQRS

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

GemFire Server GemFire 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

▪ 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

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

▪ 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

▪ 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

start.spring.io

top related