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
Docker cqrs react
ECMASCRIPT 6
DEFAULT VALUES
CLASSES
INHERITANCE
CREATE YOUR MODULES
IMPORT A MODULE
IMPORT ONLY WHAT YOU NEED
WHAT ABOUT THE UI?
Docker cqrs react
var React = require('react');

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

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

document.getElementById('app')

);
Docker cqrs react
https://kangax.github.io/compat-table/es6/
Docker cqrs react
ASSETIC CUSTOM FILTERS
Docker cqrs react
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!
Docker cqrs react
Docker cqrs react
Docker cqrs react
Docker cqrs react
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
Docker cqrs react
Docker cqrs react
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
Docker cqrs react
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
Orm hero
PDF
How to CQRS in node: Eventually Consistent, Distributed Microservice Systems..
PDF
CQRS and Event Sourcing in a Symfony application
PDF
Symfony 4 Workshop - Limenius
PDF
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
PPTX
Domain Driven Design using Laravel
PDF
Cqrs api v2
How Kris Writes Symfony Apps
Orm hero
How to CQRS in node: Eventually Consistent, Distributed Microservice Systems..
CQRS and Event Sourcing in a Symfony application
Symfony 4 Workshop - Limenius
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
Domain Driven Design using Laravel
Cqrs api v2

Similar to Docker cqrs react (20)

PDF
WebDev Crash Course
PDF
Docker Online Meetup #3: Docker in Production
PDF
Zero to scaleable in ten minutes
PPTX
Hyperledger Composer Update 2017-04-05
PDF
Beyond MVC: from Model to Domain
PPTX
REST Methodologies
PDF
Hands on kubernetes_container_orchestration
PPTX
Hypermedia APIs from Event-Driven CQRS Systems
PPTX
Our way to microservices
PDF
From development environments to production deployments with Docker, Compose,...
PDF
Symfony2 San Francisco Meetup 2009
PDF
Building APIs in an easy way using API Platform
PDF
Cqrs api
PDF
PHP Development Tools
PDF
node.js, javascript and the future
PDF
Build powerfull and smart web applications with Symfony2
PDF
Refactoring to symfony components
PDF
Nginx Internals
PDF
Modern web dev_taxonomy
KEY
Event Driven Architecture
WebDev Crash Course
Docker Online Meetup #3: Docker in Production
Zero to scaleable in ten minutes
Hyperledger Composer Update 2017-04-05
Beyond MVC: from Model to Domain
REST Methodologies
Hands on kubernetes_container_orchestration
Hypermedia APIs from Event-Driven CQRS Systems
Our way to microservices
From development environments to production deployments with Docker, Compose,...
Symfony2 San Francisco Meetup 2009
Building APIs in an easy way using API Platform
Cqrs api
PHP Development Tools
node.js, javascript and the future
Build powerfull and smart web applications with Symfony2
Refactoring to symfony components
Nginx Internals
Modern web dev_taxonomy
Event Driven Architecture
Ad

Recently uploaded (20)

PPT
Occupational Health and Safety Management System
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PPTX
Nature of X-rays, X- Ray Equipment, Fluoroscopy
PDF
Categorization of Factors Affecting Classification Algorithms Selection
PDF
Abrasive, erosive and cavitation wear.pdf
PPT
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
PPTX
Safety Seminar civil to be ensured for safe working.
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PPT
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
PPT
introduction to datamining and warehousing
PDF
Visual Aids for Exploratory Data Analysis.pdf
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PPTX
Current and future trends in Computer Vision.pptx
PDF
86236642-Electric-Loco-Shed.pdf jfkduklg
PPT
Total quality management ppt for engineering students
PPTX
UNIT 4 Total Quality Management .pptx
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
CURRICULAM DESIGN engineering FOR CSE 2025.pptx
PDF
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
Occupational Health and Safety Management System
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
Nature of X-rays, X- Ray Equipment, Fluoroscopy
Categorization of Factors Affecting Classification Algorithms Selection
Abrasive, erosive and cavitation wear.pdf
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
Safety Seminar civil to be ensured for safe working.
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
introduction to datamining and warehousing
Visual Aids for Exploratory Data Analysis.pdf
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
Current and future trends in Computer Vision.pptx
86236642-Electric-Loco-Shed.pdf jfkduklg
Total quality management ppt for engineering students
UNIT 4 Total Quality Management .pptx
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
CURRICULAM DESIGN engineering FOR CSE 2025.pptx
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
Ad

Docker cqrs react