SlideShare a Scribd company logo
CQRS, REACTJS, DOCKERIN A NUTSHELL
Andrea GiulianoClaudio D'Alicandro Simone Di Maulo
NEW AMAZING
PROJECT
WE CAN WRITE IT
FROM SCRATCH
BUT
immagine manager incazzato
WE NEED IT IN A VERY FEW TIME
AND
IT SHOULD BE
WTF!
WHERE DO WE
START?
COMFORT ZONE
DOMAIN
▸ data come from and go to external entities
▸ users can configure to send a subset of data
▸ users send data based on their plan
send data from a source to a target
GOAL
THE DOMAIN
▸ unpredictable data structures
▸ ad hoc workflow for each vendor
▸ variable number of steps
▸ handle rate limits from different vendors
▸ handle different error cases from different vendors
▸ handle business-oriented limits (based on plans...)
▸ some tasks need to be done asynchronously
IDEA
BLACK BOX REASONING
▸ identify the main entities involved
▸ define a common input and output
▸ find a way to let things talk
INPUT OUTPUT
FROM
BLACK BOXES
TO
BOUNDED CONTEXTS
DEPENDENCIES INFRA BC
MODEL
APPLICATION
PRESENTATION
PROJECT DIRECTORY TREE
APP DIRECTORY TREE
INFRASTRUCTURE DIRECTORY TREE
INSIDE THE
BOUNDED CONTEXT
BC DIRECTORY TREE
BC APPLICATION DIRECTORY TREE
BC MODEL DIRECTORY TREE
BC PRESENTATION DIRECTORY TREE
EVERYTHING'S AWESOME
▸ the framework is an
implementation detail
▸ the directory structure is
explicit
▸ the domain is isolated
WE DON'T WANT TO
MESS THINGS UP
DON'T MESS UP THINGS
WHAT'S THE ISSUE HERE
▸ understandable?
▸ code can't be reused
▸ high coupling
▸ untestable
▸ too many responsibilities
▸ hard to find bugs
▸ not changes-prone
WHAT WE WANT
COMMAND QUERY
RESPONSIBILITY
SEGREGATIONAKA CQRS
A SOLUTION
CQRS
▸ separe reads from writes
▸ commands perform actions
▸ queries return data
▸ heterogeneous data storages
▸ easy scaling
▸ deal with eventual consistency
WRITE STORAGE
QUERY
COMMAND
COMMAND
COMMAND BUS
COMMAND HANDLER
DOMAIN
REPOSITORY
READ STORAGE
REPOSITORY
EVENT BUS
EVENT SUBSCRIBER
IT'S ALL ABOUT
BUSES
IT'S ALL ABOUT
BUSES COMMUNICATION
INTERNAL COMMUNICATION
BC
EVENT
COMMAND
MESSAGE BUS
$ composer require simple-bus/message-bus
COMMANDS
COMMAND BUS
Represent the change that should be done in the domain


They are named with a verb in the imperative tense and may include
the aggregate type, for example ScheduleATask.
COMMANDS
COMMAND BUS
CONTROLLER
$commandBus->handle(

ScheduleATask::fromTaskId($taskId)

);
HANDLER
public function handle(Command $command)

{

//do something with the $command

}
EVENTS
BC 1 BC 2
EVENT BUS
An event represents something that took place in
the domain. 



They are always named with a past-participle verb,
such as TaskScheduled
EVENTS
BC 1 BC 2
EVENT BUS
subscribes_to: 'user-created'
subscribes_to: 'task-stopped'
subscribes_to: 'task-suspended'
EVENTS
BC 1 BC 2
EVENT BUS
$messageBus->handle(

UserCreatedEvent::fromUser($user)

);
subscribes_to: 'user-created'
subscribes_to: 'task-stopped'
subscribes_to: 'task-suspended'
$messageBus->handle(

TaskSuspendedEvent::fromTask($task)

);
COMMUNICATION AMONG BCS
BC 1 BC 2
QUEUE
NETWORK
QUEUE
BC 1 BC 2
QUEUE
$producer->publish($message); $consumer->consume($message);
NETWORK
BC 1 BC 2
NETWORK
$httpClient->post('/tasks/schedule');
POST /tasks/schedule
SCENARIO: TRIGGER THE TASKS SCHEDULE EVERY 10 MINUTES
TIMER
SCENARIO: TRIGGER THE TASKS SCHEDULE EVERY 10 MINUTES
TIMER SCHEDULER
POST /tasks/schedule
SCENARIO: TRIGGER THE TASKS SCHEDULE EVERY 10 MINUTES
TIMER SCHEDULER
POST /tasks/schedule
DATA STORAGE
$taskRepository->getAll()
SCENARIO: TRIGGER THE TASKS SCHEDULE EVERY 10 MINUTES
TIMER SCHEDULER
POST /tasks/schedule
DATA STORAGE
$taskRepository->getAll()
TASK QUEUE
enqueue($taskId)
SCENARIO: TRIGGER THE TASKS SCHEDULE EVERY 10 MINUTES
TIMER SCHEDULER
POST /tasks/schedule
DATA STORAGE
$taskRepository->getAll()
TASK QUEUE
enqueue($taskId)
W1 W2 W3 W..N...
LET ME SEE WHAT
YOU HAVE DONE
IT'S TIME TO SHOW DOWN
WHAT THE TEAM HAS DELIVERED
WHAT THE MANAGEMENT SEE
WHAT THE MANAGEMENT WANTS
LET'S START FROM
THE TEMPLATE
TWIG
THE FRONTEND STUFF
THE FRONTEND STUFF
ORDER DEPENDENT
THE FRONTEND STUFF
GLOBAL SCOPE
<script>

$('.btn').click(function(e){

e.stopPropagation();



// Do something cool!



});

</script>
NEVER TRUST THE GLOBAL SCOPE
A STEP
BACKWARD
WE ARE BACKEND DEVELOPERS
OUR
COMFORT ZONE
OOP
ENCAPSULATION
MODULES
DEPENDENCY
INJECTION
GOOD NEWS
CQRS, ReactJS, Docker in a nutshell
ECMASCRIPT 6
DEFAULT VALUES
CLASSES
INHERITANCE
CREATE YOUR MODULES
IMPORT A MODULE
IMPORT ONLY WHAT YOU NEED
WHAT ABOUT THE UI?
CQRS, ReactJS, Docker in a nutshell
var React = require('react');

var ReactDOM = require('react-dom');
ReactDOM.render(

<h1>Hello, world!</h1>,

document.getElementById('app')

);
CQRS, ReactJS, Docker in a nutshell
https://kangax.github.io/compat-table/es6/
CQRS, ReactJS, Docker in a nutshell
ASSETIC CUSTOM FILTERS
CQRS, ReactJS, Docker in a nutshell
ANOTHER STEP
BACKWARD
REMEMBER THE
BOUNDED CONTEXT
A LOT OF SMALL COMPONENTS
A LOT OF SMALL APPLICATIONS
BOUNDED CONTEXT FACEBOOK BOUNDED CONTEXT MAILCHIMPBOUNDED CONTEXT MAPPING
BOUNDED CONTEXT FACEBOOK BOUNDED CONTEXT MAILCHIMPBOUNDED CONTEXT MAPPING
Gulp Bundler
+
BOUNDED CONTEXT FACEBOOK BOUNDED CONTEXT MAILCHIMPBOUNDED CONTEXT MAPPING
DEVELOPMENT
WORKFLOW
$ docker/gulp
docker-compose run --rm --entrypoint bash npm -c "gulp"
// gulpfile.js

var gulp = require('gulp');

var hub = require('gulp-hub');
process

.env

.WEBPACK_CONFIG_FILE = path.join(

__dirname,

'webpack.config.js'

)

;
hub(['src/**/gulpfile.js']);
BOUNDED CONTEXT FACEBOOK BOUNDED CONTEXT MAILCHIMPBOUNDED CONTEXT MAPPING
gulpfile.js gulpfile.js gulpfile.js
BOUNDED CONTEXT FACEBOOK
gulpfile.js
"## FacebookPresentationBundle.php

$## Resources

"## assets

"## config

"## public

$## views
$ app/console assets:install
LET'S EXPOSE TO THE WEB
APPLICATION ENTRYPOINT
IT'S A BIG WORLD OUT THERE!
CQRS, ReactJS, Docker in a nutshell
CQRS, ReactJS, Docker in a nutshell
CQRS, ReactJS, Docker in a nutshell
CQRS, ReactJS, Docker in a nutshell
THE DEVELOPMENT ENVIRONMENT
▸ Easy to use so many technologies at no installation cost
▸ Prepare the scaffolding for a new developer is extremely
simple
▸ Superior performances over previous systems
docker-compose.yml docker-compose.dev.yml
THE INFRASTRUCTURE
THE INFRASTRUCTURE
THE INFRASTRUCTURE
THE INFRASTRUCTURE
THE INFRASTRUCTURE
VS
THE INFRASTRUCTURE
VS
STAGE
▸ Automate image building
▸ Copy the same structure used in dev
STAGE
▸ Automate image building
▸ Copy the same structure used in dev
AUFS: VOLUMES MIGHT BE A LITTLE HARDER THAN IT SEEMS
SYMFONY PARAMETERS
incenteev/composer-parameter-handler
DOCKER CLOUD REPOSITORY CONFIGURATION
CQRS, ReactJS, Docker in a nutshell
CQRS, ReactJS, Docker in a nutshell
DATA ONLY CONTAINER
DATA ONLY CONTAINER
DATA ONLY CONTAINER
DATA ONLY CONTAINER
FIRST DEPLOY
AN ELEPHANT IN THE ROOM... WE NEED
▸ Automated deploy strategy
▸ The freedom to easily scale
SCALE
$ docker-compose scale 
web=2 
worker=3
HARD TRUTH
fpm:
image: 'adespresso/hubespresso-staging:fpm-latest'
deployment_strategy: every_node
sequential_deployment: true
tags:
- fpm
- hubespresso
- production
volumes:
- /var/www/project
volumes_from:
- shared-fpm.hubespresso-production
SCALE CONTAINERS IS WORTHLESS IF YOU DO NOT SCALE NODES
HARD TRUTH
SCALE CONTAINERS IS WORTHLESS IF YOU DO NOT SCALE NODES
fpm:
image: 'adespresso/hubespresso-staging:fpm-latest'
deployment_strategy: every_node
sequential_deployment: true
tags:
- fpm
- hubespresso
- production
volumes:
- /var/www/project
volumes_from:
- shared-fpm.hubespresso-production
DATA ONLY CONTAINER IS A PAIN
CQRS, ReactJS, Docker in a nutshell
DEPLOYMENT
▸ deploy the infrastructure is not straightforward
▸ multiple container in multiple nodes
▸ every container has its own lifecycle
▸ we are not assuring zero-downtime on deployment
THE SOLUTION: GREEN BLUE DEPLOYMENT
THE SOLUTION: GREEN BLUE DEPLOYMENT
THE SOLUTION: GREEN BLUE DEPLOYMENT
CONCLUSION
CQRSPHP7
DOCKER
REACTJS
MONGODBWEBPACK
GULP
LEAVE THE
COMFORT ZONE
THANKS
QUESTIONS?

More Related Content

PDF
How Kris Writes Symfony Apps
PDF
Biglietti, prego! - A ticket for the (command) bus
PDF
PHP on the desktop
PDF
Scrivere e leggere log con elastic
PPTX
4Developers 2015: CQRS - Prosta architektura dla nieprostego systemu! - Mateu...
PDF
Tips and Tricks for your Service Oriented Architecture @ CakeFest 2013 in San...
PDF
MeaNstack on Docker
PDF
Functional Web Development
How Kris Writes Symfony Apps
Biglietti, prego! - A ticket for the (command) bus
PHP on the desktop
Scrivere e leggere log con elastic
4Developers 2015: CQRS - Prosta architektura dla nieprostego systemu! - Mateu...
Tips and Tricks for your Service Oriented Architecture @ CakeFest 2013 in San...
MeaNstack on Docker
Functional Web Development

Similar to CQRS, ReactJS, Docker in a nutshell (20)

PDF
Drupalcon 2023 - How Drupal builds your pages.pdf
PDF
2023 - Drupalcon - How Drupal builds your pages
PDF
Docker, Kubernetes, and Google Cloud
PDF
Into The Box 2018 Going live with commandbox and docker
PDF
Going live with BommandBox and docker Into The Box 2018
PDF
Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...
PDF
Solutions for bi-directional Integration between Oracle RDMBS & Apache Kafka
PPTX
Zero to Continuous Delivery on Google Cloud
PDF
Introduction to angular js
PDF
Burn down the silos! Helping dev and ops gel on high availability websites
PDF
Reactive.architecture.with.Angular
PDF
Deploying configurable frontend web application containers
PDF
Flask and Angular: An approach to build robust platforms
PPTX
Couch db 浅漫游.
PPTX
Single Page JavaScript WebApps... A Gradle Story
PDF
Performance measurement and tuning
PDF
Web development tools { starter pack }
PDF
High-Quality JavaScript
PDF
The Fairy Tale of the One Command Build Script
PPTX
Good karma: UX Patterns and Unit Testing in Angular with Karma
Drupalcon 2023 - How Drupal builds your pages.pdf
2023 - Drupalcon - How Drupal builds your pages
Docker, Kubernetes, and Google Cloud
Into The Box 2018 Going live with commandbox and docker
Going live with BommandBox and docker Into The Box 2018
Solutions for bi-directional integration between Oracle RDBMS and Apache Kafk...
Solutions for bi-directional Integration between Oracle RDMBS & Apache Kafka
Zero to Continuous Delivery on Google Cloud
Introduction to angular js
Burn down the silos! Helping dev and ops gel on high availability websites
Reactive.architecture.with.Angular
Deploying configurable frontend web application containers
Flask and Angular: An approach to build robust platforms
Couch db 浅漫游.
Single Page JavaScript WebApps... A Gradle Story
Performance measurement and tuning
Web development tools { starter pack }
High-Quality JavaScript
The Fairy Tale of the One Command Build Script
Good karma: UX Patterns and Unit Testing in Angular with Karma
Ad

More from Andrea Giuliano (10)

PDF
Go fast in a graph world
PDF
Concurrent test frameworks
PDF
Index management in depth
PDF
Consistency, Availability, Partition: Make Your Choice
PDF
Asynchronous data processing
PDF
Think horizontally @Codemotion
PDF
Index management in shallow depth
PDF
Everything you always wanted to know about forms* *but were afraid to ask
PDF
Stub you!
PDF
Let's test!
Go fast in a graph world
Concurrent test frameworks
Index management in depth
Consistency, Availability, Partition: Make Your Choice
Asynchronous data processing
Think horizontally @Codemotion
Index management in shallow depth
Everything you always wanted to know about forms* *but were afraid to ask
Stub you!
Let's test!
Ad

Recently uploaded (20)

PDF
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS
PDF
Exploratory_Data_Analysis_Fundamentals.pdf
PDF
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
PPTX
Current and future trends in Computer Vision.pptx
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PPTX
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
Abrasive, erosive and cavitation wear.pdf
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PPT
Total quality management ppt for engineering students
PPTX
Nature of X-rays, X- Ray Equipment, Fluoroscopy
PPT
Occupational Health and Safety Management System
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PDF
Analyzing Impact of Pakistan Economic Corridor on Import and Export in Pakist...
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
communication and presentation skills 01
PPT
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
PDF
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
PDF
737-MAX_SRG.pdf student reference guides
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS
Exploratory_Data_Analysis_Fundamentals.pdf
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
Current and future trends in Computer Vision.pptx
III.4.1.2_The_Space_Environment.p pdffdf
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
R24 SURVEYING LAB MANUAL for civil enggi
Abrasive, erosive and cavitation wear.pdf
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
Total quality management ppt for engineering students
Nature of X-rays, X- Ray Equipment, Fluoroscopy
Occupational Health and Safety Management System
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
Analyzing Impact of Pakistan Economic Corridor on Import and Export in Pakist...
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
communication and presentation skills 01
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
737-MAX_SRG.pdf student reference guides

CQRS, ReactJS, Docker in a nutshell