+ All Categories
Home > Technology > Cqrs but different

Cqrs but different

Date post: 30-Jul-2015
Category:
Upload: particular-software
View: 88 times
Download: 0 times
Share this document with a friend
33
CQRS but different Udi Dahan @udidahan in Particular
Transcript
Page 1: Cqrs but different

CQRSbut different

Udi Dahan@udidahan in Particular

Page 2: Cqrs but different

Agenda

Background

Architecture

Approach

Page 3: Cqrs but different

CQRS Background

Page 4: Cqrs but different

Why people think they need it

Scalability

Simpler code

Everybody’s talking about it

Page 5: Cqrs but different

Slave N

Scalability – DB Master/Slave

MasterClient Library

Slave 2

Slave 1

async master to slave replication

Page 6: Cqrs but different

Scalability – Partitioning

Dividing data across multiple DB instances

Requires some level of application knowledge

Page 7: Cqrs but different

Scalability – Sharding

Like partitioning, but not on a natural key

Page 8: Cqrs but different

The logical deployment architecture

Client

DB

Server

Page 9: Cqrs but different

… or even

Client

DB

Simpler code?

Page 10: Cqrs but different

Simpler by comparison?

Page 11: Cqrs but different

Everybody’s doin’ it!

Page 12: Cqrs but different

Background

Architecture

Approach

Page 13: Cqrs but different

Architecture

UI (MVC)

BL

DAL (ORM)

DB

Services

Page 14: Cqrs but different

Domain-Driven Design

Value Objects

Anti-corruption layers components

Subdomains & Bounded Contexts

Page 15: Cqrs but different

Starting up in the UI

Page 16: Cqrs but different

… and going all the way down

UI

BL

DAL

DB

API

Page 17: Cqrs but different

… and finally beyond layers

Lightweight ServiceBus (pub/sub)

BC1 BC2 BC3

NoSqlSql Shards

Page 18: Cqrs but different

SOA

EDA MVC

Pipes &Filters

REST

DDD

LayersCQRS

What to use when?

Page 19: Cqrs but different

Background

Architecture

Approach

Page 20: Cqrs but different

Where things can go wrong

High contention domains

Page 21: Cqrs but different

… on the most popular items

Page 22: Cqrs but different

Regular logic starts to choke

begin transactionvar quantity = select Q from

Inventory where Id = @ProdId

if (quantity >= quantityRequested)update Inventory set Q =quantity – quantityRequestedwhere Id = @ProdId

commit transaction

Page 23: Cqrs but different

… and the connection pool to dry up

Page 24: Cqrs but different

Resulting in terrible wait timesfor everybody

Page 25: Cqrs but different

Regular CQRS might fall behind too

Page 26: Cqrs but different

What’s great about Event Sourcingnon-blocking, append-only data model

Page 27: Cqrs but different

Business needs to get flexible

Page 28: Cqrs but different

Append-only data modelswith simple querying too

ProductID

Delta TimeStamp

5 -1 08:35:22 6-3-2015

5 -1 08:35:27 6-3-2015

5 -3 08:42:12 6-3-2015

5 +250 08:43:06 6-3-2015

5 -2 10:36:22 6-3-2015

5 -5 17:25:54 6-3-2015

5 -3 18:02:37 6-3-2015

select sum(Delta) where …

Page 29: Cqrs but different

Add snapshotting for compaction

ProductID

Delta TimeStamp

5 +235 18:03:06 6-3-2015begin transaction

select @q = sum(Delta), TimeStamp <= 5.min.ago

from Inventory where Id = @ProdIddelete from Inventory where Id =

@ProdIdand TimeStamp <= 5.min.agoinsert into Inventory @ProdId, @q,

now()commit transaction

Page 30: Cqrs but different

The logical deployment architecture

Client

DB

Server

Simple – isn’t it?

Page 31: Cqrs but different

Summary

Background

Architecture

Approach

Page 32: Cqrs but different

Want to learn more?

Page 33: Cqrs but different

Thank you

Udi Dahan@udidahan in Particular


Recommended