Optimizing the query stack of CQRS-layered applicationssddconf.com › brands › sdd › library › sdd16_esposito_querystack.pdf · Optimizing the query stack of CQRS-layered applications

Post on 23-Jun-2020

3 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

Transcript

Optimizing the query stack of CQRS-layered applications

Dino EspositoJetBrains

dino.esposito@jetbrains.com@despos

facebook.com/naa4e

Drink Eat

QueryCommand

CQRS ≈ Separating Stacks

Domain layer

Presentation layer

Application layer

Infrastructure layer

Canonical

Layered Architecture

Domain layer

Presentation layer

Application layer

Infrastructure layer

Commands Queries

Data

access

+

DTODomain layer Domain layer

CQRS

Layered Architecture

Conceptual model split into separate

models for update and display

Focus on tasks

Build the data model right for the task

Stop god-mode development

Stop wondering if your model is perfect

CQRS

Architectural spinoffs

Presentation layer

VIEWSFORMS

Infrastructure layer

Domain layer

Presentation layer

Application layer

Infrastructure layer

Commands Queries

Data

access

+

DTO

CQRS

Layered Architecture

Infrastructure layer

Synchronous

Every command triggers sync

updates

Asynchronous

Every command triggers async

updates

Scheduled

A job runs periodically and

updates the read storage

On-demand

Updates triggered by

requests (if older enough)

Automatically

up-to-date

Eventually

up-to-date

Controlled

stalenessControlled

up-to-date

CQRS for Plain CRUD Applications

Presentation

&

Application

Presentation

&

Application

YourApp.CommandStack YourApp.ReadStack

Use the code that does the job

Existing code

Existing products

Existing skills

COMMAND stack

Known patterns

Known techniques

Known practices

O/RM of choice

LINQ

Database in use

READ stackUse the code that does the job

SQL queries

Data binding/grids

JSON / OData

CQRS for Rich CRUD Applications

Presentation

&

Application

Presentation

&

Application

YourApp.CommandStack YourApp.ReadStack

COMMAND STACK

Request for action

Log of actions

READ

DATA

STORE

Aggregate ID Data

Aggregate ID Data

Request for data Formatted data

DETAILED VIEW

Logging the list of commands makes any

CRUD an historical CRUD

Logging the list of

commands lets you

keep track of the

latest without

forgetting anything

that happened in

the past.

PS: if you really want to forget … go with plain CRUD.

SELECT relevant business events

FROM System

WHERE TimeStamp BETWEEN Time1 AND Time2

SELECT relevant business events

FROM System

WHERE TimeStamp NEWER THAN Time1

SELECT relevant business events

FROM System

WHERE TimeStamp OLDER THAN Time1

REPLAY EVENTS

REBUILD THE STATECQRS leads to

Business Intelligence

Ubiquitous Language

When the language of the business is

fully replicated in the codebase

Ubiquitous

Language Query stack

public class Database : IDisposable{

private readonly QueryDbContext _db = new QueryDbContext();

public IQueryable<Customer> Customers{

get { return _db.Customers; } }public void Dispose() {

_db.Dispose(); }

}

DEMOWeb API service using OData and domain-friendly

extension methods for LINQ queries

FOLLOW

That’s All Folks!

facebook.com/naa4e

software2cents.wordpress.com

dino.esposito@jetbrains.com

@despos

top related