25
Globalcode – Open4education CQRS and Event Driven Architecture Andre Eberhardt

TDC2016POA | Trilha Arquitetura - CQRS e Event Driven Architecture valem a pena? Sim ou Claro?

Embed Size (px)

Citation preview

Page 1: TDC2016POA | Trilha Arquitetura -  CQRS e Event Driven Architecture valem a pena? Sim ou Claro?

Globalcode – Open4education

CQRS and Event Driven Architecture

Andre Eberhardt

Page 2: TDC2016POA | Trilha Arquitetura -  CQRS e Event Driven Architecture valem a pena? Sim ou Claro?

Globalcode – Open4education

whoami

/in/andreeberhardt

@aeberha

/eberhara

Software Specialist @ ADP

Page 3: TDC2016POA | Trilha Arquitetura -  CQRS e Event Driven Architecture valem a pena? Sim ou Claro?

Globalcode – Open4education

motivation

Page 4: TDC2016POA | Trilha Arquitetura -  CQRS e Event Driven Architecture valem a pena? Sim ou Claro?

Globalcode – Open4education

agenda

cqrswhat’s it?why does it matter?when should (or not) it be applied?

event driven architectureintrousage with cqrs

sample app...

Page 5: TDC2016POA | Trilha Arquitetura -  CQRS e Event Driven Architecture valem a pena? Sim ou Claro?

Globalcode – Open4education

what’s cqrs?

Command

Query

Responsibility

Segregation

Page 6: TDC2016POA | Trilha Arquitetura -  CQRS e Event Driven Architecture valem a pena? Sim ou Claro?

Globalcode – Open4education

an architectural model?

NO

Page 7: TDC2016POA | Trilha Arquitetura -  CQRS e Event Driven Architecture valem a pena? Sim ou Claro?

Globalcode – Open4education

a pattern?

YES!

Page 8: TDC2016POA | Trilha Arquitetura -  CQRS e Event Driven Architecture valem a pena? Sim ou Claro?

Globalcode – Open4education

it’s not this...

Page 9: TDC2016POA | Trilha Arquitetura -  CQRS e Event Driven Architecture valem a pena? Sim ou Claro?

Globalcode – Open4education

it could be this...

Page 10: TDC2016POA | Trilha Arquitetura -  CQRS e Event Driven Architecture valem a pena? Sim ou Claro?

Globalcode – Open4education

... or even this!

Page 11: TDC2016POA | Trilha Arquitetura -  CQRS e Event Driven Architecture valem a pena? Sim ou Claro?

Globalcode – Open4education

so, why does it matter?

Scalability

Reduce complexity (domain level)

Flexibility

Focus on domain logic / proper technology

Task-based operations / Stale data

Page 12: TDC2016POA | Trilha Arquitetura -  CQRS e Event Driven Architecture valem a pena? Sim ou Claro?

Globalcode – Open4education

but... and the downsides?

Learning curve / fear of change

Complexity

Eventual consistency

"Most people using CQRS (and event sourcing too) shouldn't have done so." —Udi Dahan

Page 13: TDC2016POA | Trilha Arquitetura -  CQRS e Event Driven Architecture valem a pena? Sim ou Claro?

Globalcode – Open4education

so when should I apply it?

Decision per Bounded Context

Collaborative / complex domainsMultiple operations in parallel (stale data)

Distributed / specialized teams

Command vs Read performance

Page 14: TDC2016POA | Trilha Arquitetura -  CQRS e Event Driven Architecture valem a pena? Sim ou Claro?

Globalcode – Open4education

and when avoid it?

Simple / static CRUD

Sequential operations

Non-collaborative bounded contexts

Eventual consistency not acceptable

Page 15: TDC2016POA | Trilha Arquitetura -  CQRS e Event Driven Architecture valem a pena? Sim ou Claro?

Globalcode – Open4education

event driven architecture

Page 16: TDC2016POA | Trilha Arquitetura -  CQRS e Event Driven Architecture valem a pena? Sim ou Claro?

Globalcode – Open4education

what’s that now?

State changes

Event consumers vs producers

Fire-and-forget

Happens in the past“User created”, “User deleted”, ...

Page 17: TDC2016POA | Trilha Arquitetura -  CQRS e Event Driven Architecture valem a pena? Sim ou Claro?

Globalcode – Open4education

and why is that good?

Immutable states

Loosely coupled apps

Fits well with some rock stars (CQRS and DDD)

Async process

State reproducibility

Page 18: TDC2016POA | Trilha Arquitetura -  CQRS e Event Driven Architecture valem a pena? Sim ou Claro?

Globalcode – Open4education

request-driven soa

Page 19: TDC2016POA | Trilha Arquitetura -  CQRS e Event Driven Architecture valem a pena? Sim ou Claro?

Globalcode – Open4education

event driven architecture

Page 20: TDC2016POA | Trilha Arquitetura -  CQRS e Event Driven Architecture valem a pena? Sim ou Claro?

Globalcode – Open4education

cqrs without events...

Page 21: TDC2016POA | Trilha Arquitetura -  CQRS e Event Driven Architecture valem a pena? Sim ou Claro?

Globalcode – Open4education

cqrs and events?!

Page 22: TDC2016POA | Trilha Arquitetura -  CQRS e Event Driven Architecture valem a pena? Sim ou Claro?

Globalcode – Open4education

lessons learned

Start small and extensible

Scale when you need to scaleAvoid huge / complex architectures for small problemsAvoid scaling when you don’t need to

Page 23: TDC2016POA | Trilha Arquitetura -  CQRS e Event Driven Architecture valem a pena? Sim ou Claro?

Globalcode – Open4education

gurus

Greg Young

Martin Fowler

Udi Dahan

Page 24: TDC2016POA | Trilha Arquitetura -  CQRS e Event Driven Architecture valem a pena? Sim ou Claro?

Globalcode – Open4education

sample app...

https://github.com/eberhara/sample-cqrs

Page 25: TDC2016POA | Trilha Arquitetura -  CQRS e Event Driven Architecture valem a pena? Sim ou Claro?

Globalcode – Open4education

thank you :)

/in/andreeberhardt

@aeberha

/eberhara