Нарушение DRY принципа особенно часто возникает в микросервисах. Чтобы избежать этой проблемы, вы можете использовать повторно используемые компоненты, например, приватные пакеты npm. Лучшие практики, которые помогут вам достичь этого включают в себя паттерн ECB для организации кода, манифест 12-ти факторного приложения, использование генерации кода. В нашем проекте мы используем технический стек на основе Node.js, Docker, RabbitMQ, но идеи из этого доклада могут быть использованы для любого технического стека микросервисов
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
9. 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
39. 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
64. 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.
65. 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
67. ▰ Wrapper for Enterprise Bus
▰ File Storage wrapper
(S3/Local FileSystem)
▰ JSON RPC with different
transports
Possible Boundaries Components
67
68. 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
70. 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
72. microservices base application with:
▰ Base boundary class
▰ App class with start stop
▰ Default logger
▰ Hooks
Basement
72
73. 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
80. 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
81. 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
82. 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
89. 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