going serverless with cqrs on aws

Post on 12-Apr-2017

794 Views

Category:

Software

12 Downloads

Preview:

Click to see full reader

TRANSCRIPT

GOING SERVERLESS WITH CQRS ON AWSJavaDay Kyiv 10.2016

Anton Udovychenko

ABOUT ME Software Architect @ Levi9 8+ years of Java experience AWS Certified Architect Passionate about agile methodology and clean code

https://www.linkedin.com/in/antonudovychenko

http://www.slideshare.net/antonudovychenko

AGENDA•What is Serverless?• Event Sourcing• CQRS•Demo•Downsides of Serverless•Q&A

MAIN SERVERLESS VENDORS

EVERYTHING WAS A LIE

Serverless architecture has servers

WHAT IS SERVERLESS Backend as a Service (rich frontend client)

Cognito DynamoDB SES

S3 Kinesis

WHAT IS SERVERLESS Function as a Service

Cognito

DynamoDB

SES

S3

Kinesis

Lambda

AWS LAMBDA AWS Lambda lets you run code without provisioning or managing servers. You pay only for the compute time you consume - there is no

charge when your code is not running.

Lambda

AWS LAMBDA AWS Lambda lets you run code without provisioning or managing servers. You pay only for the compute time you consume - there is no

charge when your code is not running.

Lambda

Function as a unit of scale

AWS LAMBDA AWS Lambda lets you run code without provisioning or managing servers. You pay only for the compute time you consume - there is no

charge when your code is not running.

Lambda

Function as a unit of scale Abstracts the language runtime

AWS LAMBDA AWS Lambda lets you run code without provisioning or managing servers. You pay only for the compute time you consume - there is no

charge when your code is not running.

Lambda

Function as a unit of scale Abstracts the language runtime

Never pay for idle

AWS LAMBDA AWS Lambda lets you run code without provisioning or managing servers. You pay only for the compute time you consume - there is no

charge when your code is not running.

≠ No OpsLambda

STANDARD MONOLITHIC APPLICATION

Application Database

SERVERLESS APPLICATION

Authentication service Database

API Gateway

Function 1

Function 2

Function N

SERVERLESS APPLICATION WITH AWS

Cognito

API Gateway Database

Function 1

Function 2

Function N

SERVERLESS APPLICATION WITH AWS

Cognito API Gateway

Database

Function 1

Function 2

Function N

SERVERLESS APPLICATION WITH AWS

Cognito API Gateway

Lambda

Lambda…

Lambda

Database

SERVERLESS APPLICATION WITH AWS

Lambda

Lambda

Lambda

…API GatewayCognito RDS

AWS SERVERLESS FLAVOURS• Serverless backend

one function per REST API endpoint

• Event handlersone function per event type (scheduled, S3, Kinesis, DynamoDB,

SNS, etc)

• Mobile Logicone function per SDK call

AWS LAMBDA EXAMPLE USE CASES• Scheduled infrastructure tasks (e. g. turn on/off EC2 on schedule)• Backup creation, validation• Log analysis on the fly• Processing of uploaded files• Regular calculation on the database• Filtering and transforming data on the fly

MICROSERVICES

I HEARD YOU LIKE

MICROSERVICES

I HEARD YOU LIKE

SERVERLESS IS THE NEXT LEVEL OF MICROSERVICES

BENEFITS OF SERVERLESS• No server management

BENEFITS OF SERVERLESS• No server management• Simplicity

BENEFITS OF SERVERLESS• No server management• Simplicity• Time to market

BENEFITS OF SERVERLESS• No server management• Simplicity• Time to market• Pay only for the compute you need

BENEFITS OF SERVERLESS• No server management• Simplicity• Time to market• Pay only for the compute you need• Puts focus on code performance

BENEFITS OF SERVERLESS• No server management• Simplicity• Time to market• Pay only for the compute you need• Puts focus on code performance• Good ecosystem

BENEFITS OF SERVERLESS• No server management• Simplicity• Time to market• Pay only for the compute you need• Puts focus on code performance• Good ecosystem• Automatic horizontal scaling

EVENT SOURCING

Event Sourcing ensures that all changes to application state are stored as a sequence of events

Martin Fowler

EVENT SOURCING

State is transient

We only store facts

EVENT SOURCING

State is transient

We only store facts

State = (Events)

EVENT SOURCING

State is transient

We only store facts

State = (Events)

Events (facts) are immutable:• No updates, no

deletes• Only appends• Non blocking• Store all information

EVENT SOURCING EXAMPLE

id Events Time States1 - 13:01 20 available laptops

Warehouse event store

EVENT SOURCING EXAMPLE

id Events Time States1 - 13:01 20 available laptops

2 Created order #33 by Order #1

(3 laptops)13:29 17 available and

3 reserved laptops

Warehouse event store

EVENT SOURCING EXAMPLE

id Events Time States1 - 13:01 20 available laptops

2 Created order #33 by Order #1

(3 laptops)13:29 17 available and

3 reserved laptops

3 Created order #34 by Order #2

(2 laptops)13:31 15 available and

5 reserved laptops

Warehouse event store

EVENT SOURCING EXAMPLE

id Events Time States1 - 13:01 20 available laptops

2 Created order #33 by Order #1

(3 laptops)13:29 17 available and

3 reserved laptops

3 Created order #34 by Order #2

(2 laptops)13:31 15 available and

5 reserved laptops

4 Order #33 confirmed 13:38 15 available and2 reserved and 3 bought laptops

Warehouse event store

EVENT SOURCING EXAMPLE

id Events Time States1 - 13:01 20 available laptops

2 Created order #33 by Order #1

(3 laptops)13:29 17 available and

3 reserved laptops

3 Created order #34 by Order #2

(2 laptops)13:31 15 available and

5 reserved laptops

4 Order #33 confirmed 13:38 15 available and2 reserved and 3 bought laptops

5 Order #34 cancelled 13:39 17 available and 3 bought laptops

Warehouse event store

CQSCommand-Query Separation is a division of write functions and read functions

CQSCommand-Query Separation is a division of write functions and read functions

interface OrderService { //commands void createOrder(Order order); void updateOrder(Order order); void deleteOrder(Long id);

//queries Order getOrder(Long id); List<Order> getOrders();}

CQSCommand-Query Separation is a division of write functions and read functions

interface OrderService { //commands void createOrder(Order order); void updateOrder(Order order); void deleteOrder(Long id);

//queries Order getOrder(Long id); List<Order> getOrders();}

Write functions (Commands) must not return a value

CQSCommand-Query Separation is a division of write functions and read functions

interface OrderService { //commands void createOrder(Order order); void updateOrder(Order order); void deleteOrder(Long id);

//queries Order getOrder(Long id); List<Order> getOrders();}

Write functions (Commands) must not return a value

Read functions (Queries) must have no side effects

CQRS

CQRS (Command Query Responsibility Segregation) is simply the creation of two objects where there was previously only one

Greg Young

CQRS CQRS is simply the creation of two objects where there was previously only one

Greg Young

interface OrderWriteService { void createOrder(Order order); void updateOrder(Order order); void deleteOrder(Long id);}

interface OrderReadService { Order getOrder(Long id); List<Order> getOrders();}

CQRS BENEFITS• Separate Domain Models for Query and for Command• Eventually Consistent• Polyglot Persistence• Optimized for Reads!

Query serviceQuery service

CQRS

UI

Query service

Command service

Messaging

Event Store

State StoreState StoreState Store

Command/Validation Error

Query / Result(DTO)

Event

Request

Query serviceQuery service

CQRS DEMO

UI

Query service

Command service

Messaging

Event Store

State StoreState StoreState Store

Command/Validation Error

Query / Result(DTO)

Event

Request

SERVERLESS CQRS DEMO ON AWS

S3 Event

Query / Result(DTO)

Event

Request

Lambda - Command

Lambda - Query

SQS – Message queue Lambda - Connector

S3

API Gateway

RDS – Event Store

DynamoDB – State Store

DEMO TIME

DRAWBACKS OF SERVERLESS

NO

CURRENT DRAWBACKS OF SERVERLESS • Very young

CURRENT DRAWBACKS OF SERVERLESS • Very young• Functional and Integrational testing

CURRENT DRAWBACKS OF SERVERLESS • Very young• Functional and Integrational testing• Debugging

CURRENT DRAWBACKS OF SERVERLESS • Very young• Functional and Integrational testing• Debugging• Stateless

CURRENT DRAWBACKS OF SERVERLESS • Very young• Functional and Integrational testing• Debugging• Stateless• Startup latency

CURRENT DRAWBACKS OF SERVERLESS • Very young• Functional and Integrational testing• Debugging• Stateless• Startup latency• Deployment versioning

CURRENT DRAWBACKS OF SERVERLESS • Very young• Functional and Integrational testing• Debugging• Stateless• Startup latency• Deployment versioning• Logic split

CURRENT DRAWBACKS OF SERVERLESS • Very young• Functional and Integrational testing• Debugging• Stateless• Startup latency• Deployment versioning• Logic split• Discovery

CURRENT DRAWBACKS OF SERVERLESS • Very young• Functional and Integrational testing• Debugging• Stateless• Startup latency• Deployment versioning• Logic split• Discovery• Frameworks

CURRENT DRAWBACKS OF SERVERLESS • Very young• Functional and Integrational testing• Debugging• Stateless• Startup latency• Deployment versioning• Logic split• Discovery• Frameworks

THANK YOU

github.com/terrafant/aws-lambda-cqrs www.slideshare.net/antonudovychenko

top related