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

Microservice Architecture with Reusable Components at JSFest

Microservice Architecture with Reusable Components at JSFest

Nikita Galkin

March 30, 2018
Tweet

More Decks by Nikita Galkin

Other Decks in Programming

Transcript

  1. Nikita Galkin Love and Know: ▰ How to make developers

    and business happy ▰ Technical and process debt elimination Believe that: ▰ Any problem must be solved at the right level ▰ Software is easy. People are hard ▰ A problem should be highlighted, an idea should be "sold", a solution should be demonstrated Links: Site GitHub Twitter Facebook 3
  2. 4

  3. 7 “Almost all the successful microservice stories have started with

    a monolith that got too big and was broken up” from MonolithFirst Martin Fowler
  4. 8

  5. 9 “I picked Java because I felt the most people

    would be able to understand the code examples if they were written in Java. That was the case in 1997, but how about in 2017? … But I went for the alternative: JavaScript.” 27 March 2018
  6. Scoped packages 18 ▶ npm install @zorg/zf + @zorg/[email protected] added

    1 package in 1.727s ▶ cat ~/.npmrc @zorg:registry=http://npm.zorg-weapon.com
  7. 19

  8. 20

  9. 23

  10. 26

  11. npm i -g how-to-npm how-to-npm Or Free 1,5 hour-long video:

    How to Write an Open Source JavaScript Library
  12. ▰ npx scripts ▻ eslint helper ▰ plop ▰ yeoman.io

    ▰ raml2html Code, spec, docs generators 36
  13. Test Driven Development 38 FAIL PASS TDD REFACTORING “Repetition of

    a very short development cycle: requirements are turned into very specific test cases, then the software is improved to pass the new tests, only.” Kent Beck
  14. Types or Documentation Driven Development 39 tsc Add JSDoc TDD

    ▰ choose typescript or JSDoc ▰ autocomplete for engineers ▰ always actual code documentation ▰ puppeteer source-code is awesome JSDoc example REFACTORING
  15. /** * @typedef {Object} CoverageEntry * @property {string} url *

    @property {string} text * @property {!Array<!{start: number, end: number}>} ranges */
  16. ECB is a variant of Model/View/Controller (MVC). It was published

    by Ivar Jacobson (Ericsson Co.) in the 80's with a focus on separating responsibilities of elements in Object Oriented Systems.
  17. Boundary – objects that interface with system actors (e.g. a

    user or external service). Side effected. Boundary component should be reusable. EBC Pattern – Boundary 65
  18. ▰ Wrapper for Enterprise Bus ▰ File Storage wrapper (S3/Local

    FileSystem) ▰ JSON RPC with different transports Possible Boundaries Components 67
  19. Control – objects that implement business logic. This code has

    the main value for business. This part of every microservice is unique. EBC Pattern – Control 68
  20. Entity – objects representing system data, often from the domain

    model. In our application we use an entity also for transforming data from one format to another. For example, from XML to JSON. Entity can be shared between applications as interfaces or components. EBC Pattern – Entity 70
  21. microservices base application with: ▰ Base boundary class ▰ App

    class with start stop ▰ Default logger ▰ Hooks Basement 72
  22. 1. Only Boundary provide services for the "other world". 2.

    Boundary can call only to Control. 3. Control can call anybody. 4. Entity can't call anybody (!), only be called. EBC Pattern 73
  23. 1. Attach uncaught exception hooks. 2. Log start of bootstrapping.

    3. Verify configuration. 4. Init boundaries and controls. 5. Attach shutdown hooks. 6. Log finish of bootstrapping. Bootstrapping 78
  24. For graceful shutdown application should: 1. Log start of graceful

    shutdown. 2. Close incoming boundaries. For example, stop accepting new tasks for processing from queue, stop handling new incoming http requests, etc. Graceful shutdown 80
  25. 3. Set a forced timeout for completion current tasks or

    save them for future processing. Recommended value for this timeout is not more then 5 second. 4. Notify consumers about shutdown. For example, send heartbeat-shutdown. Graceful shutdown 81
  26. 5. Correctly disconnect from all connections. For example, database, RabbitMQ,

    Redis, etc. 6. Log finish of graceful shutdown and stop the process. Graceful shutdown 82
  27. ▰ Reusable Components ▰ Monolith First ▰ The Twelve Factors

    ▰ EСB (Entity, Boundary, Control) Pattern ▰ Bootstrapping and Graceful shutdown Microservice Best Practises 84
  28. 89 Thank you for attention! Be consistent in your microservices!!!

    You can find me on Twitter as @galk_in Slides are available at speakerdeck.com/galkin or on my site galk.in
  29. ▰ koa ▰ bunyan ▰ dotenv-safe ▰ gatsbyjs ▰ rxjs

    My favorite packages 91 ▰ pre-commit ▰ eslint ▰ jest ▰ raml-cli ▰ dredd