Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Microservice
Architecture with
Reusable Components
Mar 30, 2018
Slides JSFest bot
Nikita
Galkin
Love and Know:
▰ How to make developers and business happy
▰ Technical and process debt elimination
Believe ...
4
5
“Wanna do something
good, do it yourself”
Jean-Baptiste
Emanuel Zorg
(Gary Oldman)
7
“Almost all the successful
microservice stories have started
with a monolith that got too big and
was broken up”
from Mo...
8
9
“I picked Java because I felt the most
people would be able to understand
the code examples if they were
written in Java...
Components
Best
Practices
Reusable Components
14
Why?
15
Don’t
Repeat
Yourself
16
What?
17
Scoped packages
Scoped packages
18
▶ npm install @zorg/zf
+ @zorg/zf@1.0.5
added 1 package in 1.727s
▶ cat ~/.npmrc
@zorg:registry=http://...
19
20
First package
21
▰ @your-scope/code-style
▰ Code Style and Violence
by Anton Nemtsev
22
What is not
reusable
component?
23
“Small, autonomous
services that work
together.
24
Evolution
26
27
How?
28
Robustness
Engineered for engineers
Useful
Simple
Examples included
npm i -g how-to-npm
how-to-npm
Or
Free 1,5 hour-long video:
How to Write an Open
Source JavaScript Library
Git flow
30How to convince the team?
31
How to convince the manager?
“Wanna do
something good,
do it yourself”
Zorg
“Wanna do
something good,
do it yourself”
Zorg
“Don't use require(../../utils/logger),
use npm packages” © Galkin
Awesome Pair!
But how reuse code...
Microservices
35
How to develop
reusable
components?
▰ npx scripts
▻ eslint helper
▰ plop
▰ yeoman.io
▰ raml2html
Code, spec, docs generators
36
Generators
37
Test Driven Development
38
FAIL
PASS
TDD
REFACTORING
“Repetition of a very short
development cycle: requirements are
turne...
Types or Documentation Driven Development
39
tsc
Add JSDoc
TDD
▰ choose typescript or JSDoc
▰ autocomplete for engineers
▰...
/**
* @typedef {Object} CoverageEntry
* @property {string} url
* @property {string} text
* @property {!Array<!{start: numb...
Theft Driven Development
41
STEAL
ADOPT
TDD
SHARE
Reusable Components
I'll show you my
package.json
during speaker
corner
44
Where?
Source code
storage
CI for
build and test
Artifact
storage
Git flow
46
Gitflow
Git flow
47
Gitflow
Github Flow
Monorepo with Lerna
Or one repo for one component?
Your DevOps Engineer: @#_$!
Your DevOps Engineer: @#_$!
12factor.net
“II. Dependencies
Explicitly declare and
isolate dependencies
54
“III. Config
Store config in the
environment
55
“V. Build, release, run
Strictly separate build and
run stages
56
“VI. Processes
Execute the app as one or
more stateless processes
58
“XI. Logs
Treat logs as event
streams
59
stdout stderr
61
How to develop
microservices?
MonolithFirst
How your system works?
ECB is a variant of Model/View/Controller (MVC). It
was published by Ivar Jacobson (Ericsson Co.) in
the 80's with a focus...
Boundary – objects that interface with system
actors (e.g. a user or external service). Side
effected.
Boundary component ...
Boundary place for validation
▰ Wrapper for Enterprise Bus
▰ File Storage wrapper
(S3/Local FileSystem)
▰ JSON RPC with different
transports
Possible Bo...
Control – objects that implement business
logic. This code has the main value for
business.
This part of every microservic...
Control – just control.
Entity – objects representing system data,
often from the domain model. In our
application we use an entity also for
trans...
Entity for data transform
microservices base application with:
▰ Base boundary class
▰ App class with start stop
▰ Default logger
▰ Hooks
Basement
72
1. Only Boundary provide services for the
"other world".
2. Boundary can call only to Control.
3. Control can call anybody...
74
Why does it matter?
Bootstrapping and Graceful
shutdown
Interface Microservice {
void start();
void stop();
}
Microservice interface
76
Bootstrapping
1. Attach uncaught exception hooks.
2. Log start of bootstrapping.
3. Verify configuration.
4. Init boundaries and control...
Graceful Shutdown
For graceful shutdown application should:
1. Log start of graceful shutdown.
2. Close incoming boundaries. For example,
st...
3. Set a forced timeout for completion current
tasks or save them for future processing.
Recommended value for this timeou...
5. Correctly disconnect from all connections.
For example, database, RabbitMQ, Redis,
etc.
6. Log finish of graceful shutd...
83Let’s summarize!
▰ Reusable Components
▰ Monolith First
▰ The Twelve Factors
▰ EСB (Entity, Boundary, Control) Pattern
▰ Bootstrapping and ...
85
Robustness
Engineered for engineers
Useful
Simple
Examples included
89
Thank you for attention!
Be consistent in your
microservices!!!
You can find me on Twitter as @galk_in
Slides are avail...
Slides JSFest bot
▰ koa
▰ bunyan
▰ dotenv-safe
▰ gatsbyjs
▰ rxjs
My favorite packages
91
▰ pre-commit
▰ eslint
▰ jest
▰ raml-cli
▰ dredd
JS Fest 2018. Никита Галкин. Микросервисная архитектура с переиспользуемыми компонентами
JS Fest 2018. Никита Галкин. Микросервисная архитектура с переиспользуемыми компонентами
JS Fest 2018. Никита Галкин. Микросервисная архитектура с переиспользуемыми компонентами
JS Fest 2018. Никита Галкин. Микросервисная архитектура с переиспользуемыми компонентами
JS Fest 2018. Никита Галкин. Микросервисная архитектура с переиспользуемыми компонентами
JS Fest 2018. Никита Галкин. Микросервисная архитектура с переиспользуемыми компонентами
Upcoming SlideShare
Loading in …5
×

JS Fest 2018. Никита Галкин. Микросервисная архитектура с переиспользуемыми компонентами

99 views

Published on

Нарушение DRY принципа особенно часто возникает в микросервисах. Чтобы избежать этой проблемы, вы можете использовать повторно используемые компоненты, например, приватные пакеты npm. Лучшие практики, которые помогут вам достичь этого включают в себя паттерн ECB для организации кода, манифест 12-ти факторного приложения, использование генерации кода. В нашем проекте мы используем технический стек на основе Node.js, Docker, RabbitMQ, но идеи из этого доклада могут быть использованы для любого технического стека микросервисов

Published in: Education
  • Be the first to comment

  • Be the first to like this

JS Fest 2018. Никита Галкин. Микросервисная архитектура с переиспользуемыми компонентами

  1. 1. Microservice Architecture with Reusable Components Mar 30, 2018
  2. 2. Slides JSFest bot
  3. 3. 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
  4. 4. 4
  5. 5. 5 “Wanna do something good, do it yourself” Jean-Baptiste Emanuel Zorg (Gary Oldman)
  6. 6. 7 “Almost all the successful microservice stories have started with a monolith that got too big and was broken up” from MonolithFirst Martin Fowler
  7. 7. 8
  8. 8. 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
  9. 9. Components
  10. 10. Best Practices
  11. 11. Reusable Components
  12. 12. 14 Why?
  13. 13. 15 Don’t Repeat Yourself
  14. 14. 16 What?
  15. 15. 17 Scoped packages
  16. 16. Scoped packages 18 ▶ npm install @zorg/zf + @zorg/zf@1.0.5 added 1 package in 1.727s ▶ cat ~/.npmrc @zorg:registry=http://npm.zorg-weapon.com
  17. 17. 19
  18. 18. 20
  19. 19. First package 21 ▰ @your-scope/code-style ▰ Code Style and Violence by Anton Nemtsev
  20. 20. 22 What is not reusable component?
  21. 21. 23
  22. 22. “Small, autonomous services that work together. 24
  23. 23. Evolution
  24. 24. 26
  25. 25. 27 How?
  26. 26. 28 Robustness Engineered for engineers Useful Simple Examples included
  27. 27. npm i -g how-to-npm how-to-npm Or Free 1,5 hour-long video: How to Write an Open Source JavaScript Library
  28. 28. Git flow 30How to convince the team?
  29. 29. 31 How to convince the manager?
  30. 30. “Wanna do something good, do it yourself” Zorg
  31. 31. “Wanna do something good, do it yourself” Zorg
  32. 32. “Don't use require(../../utils/logger), use npm packages” © Galkin Awesome Pair! But how reuse code... Microservices
  33. 33. 35 How to develop reusable components?
  34. 34. ▰ npx scripts ▻ eslint helper ▰ plop ▰ yeoman.io ▰ raml2html Code, spec, docs generators 36
  35. 35. Generators 37
  36. 36. 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
  37. 37. 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
  38. 38. /** * @typedef {Object} CoverageEntry * @property {string} url * @property {string} text * @property {!Array<!{start: number, end: number}>} ranges */
  39. 39. Theft Driven Development 41 STEAL ADOPT TDD SHARE
  40. 40. Reusable Components
  41. 41. I'll show you my package.json during speaker corner
  42. 42. 44 Where?
  43. 43. Source code storage CI for build and test Artifact storage
  44. 44. Git flow 46 Gitflow
  45. 45. Git flow 47 Gitflow
  46. 46. Github Flow
  47. 47. Monorepo with Lerna
  48. 48. Or one repo for one component?
  49. 49. Your DevOps Engineer: @#_$!
  50. 50. Your DevOps Engineer: @#_$!
  51. 51. 12factor.net
  52. 52. “II. Dependencies Explicitly declare and isolate dependencies 54
  53. 53. “III. Config Store config in the environment 55
  54. 54. “V. Build, release, run Strictly separate build and run stages 56
  55. 55. “VI. Processes Execute the app as one or more stateless processes 58
  56. 56. “XI. Logs Treat logs as event streams 59
  57. 57. stdout stderr
  58. 58. 61 How to develop microservices?
  59. 59. MonolithFirst
  60. 60. How your system works?
  61. 61. 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.
  62. 62. 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
  63. 63. Boundary place for validation
  64. 64. ▰ Wrapper for Enterprise Bus ▰ File Storage wrapper (S3/Local FileSystem) ▰ JSON RPC with different transports Possible Boundaries Components 67
  65. 65. 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
  66. 66. Control – just control.
  67. 67. 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
  68. 68. Entity for data transform
  69. 69. microservices base application with: ▰ Base boundary class ▰ App class with start stop ▰ Default logger ▰ Hooks Basement 72
  70. 70. 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
  71. 71. 74 Why does it matter?
  72. 72. Bootstrapping and Graceful shutdown
  73. 73. Interface Microservice { void start(); void stop(); } Microservice interface 76
  74. 74. Bootstrapping
  75. 75. 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
  76. 76. Graceful Shutdown
  77. 77. 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
  78. 78. 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
  79. 79. 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
  80. 80. 83Let’s summarize!
  81. 81. ▰ Reusable Components ▰ Monolith First ▰ The Twelve Factors ▰ EСB (Entity, Boundary, Control) Pattern ▰ Bootstrapping and Graceful shutdown Microservice Best Practises 84
  82. 82. 85 Robustness Engineered for engineers Useful Simple Examples included
  83. 83. 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
  84. 84. Slides JSFest bot
  85. 85. ▰ koa ▰ bunyan ▰ dotenv-safe ▰ gatsbyjs ▰ rxjs My favorite packages 91 ▰ pre-commit ▰ eslint ▰ jest ▰ raml-cli ▰ dredd

×