Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CQRS, React, Docker in a Nutshell

CQRS, React, Docker in a Nutshell

An journey in the world of Domain Driven Design using Command Query Responsibility Segregation, React and Docker as a deployment tool

Claudio D'Alicandro

March 31, 2016
Tweet

Other Decks in Programming

Transcript

  1. BUT

  2. AND

  3. 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
  4. 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
  5. BLACK BOX REASONING ▸ identify the main entities involved ▸

    define a common input and output ▸ find a way to let things talk INPUT OUTPUT
  6. EVERYTHING'S AWESOME ▸ the framework is an implementation detail ▸

    the directory structure is explicit ▸ the domain is isolated
  7. WHAT'S THE ISSUE HERE ▸ understandable? ▸ code can't be

    reused ▸ high coupling ▸ untestable ▸ too many responsibilities ▸ hard to find bugs ▸ not changes-prone
  8. CQRS ▸ separe reads from writes ▸ commands perform actions

    ▸ queries return data ▸ heterogeneous data storages ▸ easy scaling ▸ deal with eventual consistency
  9. WRITE STORAGE QUERY COMMAND COMMAND COMMAND BUS COMMAND HANDLER DOMAIN

    REPOSITORY READ STORAGE REPOSITORY EVENT BUS EVENT SUBSCRIBER
  10. 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.
  11. 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
  12. EVENTS BC 1 BC 2 EVENT BUS subscribes_to: 'user-created' subscribes_to:

    'task-stopped' subscribes_to: 'task-suspended'
  13. 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)
 );
  14. SCENARIO: TRIGGER THE TASKS SCHEDULE EVERY 10 MINUTES TIMER SCHEDULER

    POST /tasks/schedule DATA STORAGE $taskRepository->getAll()
  15. SCENARIO: TRIGGER THE TASKS SCHEDULE EVERY 10 MINUTES TIMER SCHEDULER

    POST /tasks/schedule DATA STORAGE $taskRepository->getAll() TASK QUEUE enqueue($taskId)
  16. 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 ...
  17. OOP

  18. // 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']);
  19. 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
  20. AN ELEPHANT IN THE ROOM... WE NEED ▸ Automated deploy

    strategy ▸ The freedom to easily scale
  21. 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
  22. 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
  23. 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