SlideShare uma empresa Scribd logo
1 de 87
Baixar para ler offline
OdessaJS - 2020
Effective NodeJS
Development
Viktor Turskyi
Viktor Turskyi
● CEO and principal software
architect at WebbyLab
● Open source developer
● More than 15 years of experience
● Delivered more than 60 projects
of different scale
● Did projects for 5 companies
from Fortune 500 list
2/86
Simple mental model for:
● Solution architecture
● Application architecture
(https://www.youtube.com/watch?v=TjvIEgBCxZo)
● Development process
● Deployment process
How to make development more
effective?
3/86
Solved most of the standard edge cases in starter-kit:
● Folders structure
● Configs
● Sessions
● Error handling
● Transactions
● Dependencies management
(including 3rd party services)
● Tests etc
How to make development more
effective?
4/86
5/86
Complex is easy. Simple is hard.
● Define standard technology stack
● Define standard architecture
● Define the most effective software development
approaches
● Define the most effective deployment strategies
● Define the most effective way of production support
● Internal trainings
Engineering productivity group
7/86
● NodeJS
● ReactJS
● React Native
● MySQL/Postgres
● S3 like object storage
● Docker
Standard technology stack
8/86
Example Project
Solution architecture overview
Monolith or Microservices by default?
"If you cannot build a monolith what makes you
think that you can build Distributed Microservices"
Simon Brown
● High operational complexity (increases costs)
● Versions compatibility issues (harder to track all dependencies in
consistent state, reduces iterations speed)
● Extremely hard to support transactions (risks of inconsistencies)
● Distribution issues (harder to program)
● Traceability issues (harder to debug)
● Technology diversity (mixing languages increases support costs,
standardization issues, hiring issues etc)
● You need more experienced team (hiring issues)
Microservices drawbacks
13/86
Key microservices issue
What is the best architectural
decision?
“The job of architect is not to make decision, the job of
the architect is to defer decisions as long as possible”
“Good architecture maximizes number
of decisions not made”
Robert Martin
https://www.youtube.com/watch?v=o_TH-Y78tt4
● But when your components are services with remote
communications, then refactoring is much harder than with
in-process libraries.
● Another issue is If the components do not compose cleanly,
then all you are doing is shifting complexity from inside a
component to the connections between components. Not
just does this just move complexity around, it moves it to a
place that's less explicit and harder to control.
https://martinfowler.com/bliki/MonolithFirst.html
Martin Fowler:
17/86
So, we start with monolith
in 90% of cases
What is Monolith?
Usually it looks like
20/86
9/19
21/86
9/19
21/86
Application architecture
Which web-framework to choose?
● Express
● Koa
● Sails
● Nest
● Feathers
● Derby
● Kraken
● Hapi etc
NodeJs frameworks:
25/86
It doesn’t matter!
Your application architecture
should not depend on a web
framework
● NodeJs: Express
● PHP: Slim3
● Perl : Mojolicious
Web frameworks we use
28/86
“We use MVC why do we need
another architecture?”
MVC (from wikipedia)
30/86
Where to place this code? Model
or Controller?
“The M in MVC: Why Models are Misunderstood
and Unappreciated” Pádraic Brady
http://blog.astrumfutura.com/2008/12/the-m-in-mvc-w
hy-models-are-misunderstood-and-unappreciated/
Fat Stupid Ugly Controllers
32/86
Is Model (MVC) and
Domain Model the same?
● Domain model
● Transaction script
● Table module
● Service layer
Model (from MVC)/Domain Logic
34/86
An object model of the domain that incorporates
both behavior and data. (M. Fowler)
Works well for medium and large applications.
Domain model
35/86
Organizes business logic by procedures where
each procedure handles a single request from the
presentation (M. Fowler).
Works well for small projects.
Transaction script
36/86
Controllers
Services
Domain model
Data access
layer
Dispatcher
How do we cook the service layer?
Separate service class (implemented
as command) for each endpoint
42/86
Real code (with meta
programming)
43/86
● Extremely thin layer
● Protects underneath layers from
everything related to HTTP
● If you change JSON to XML (or even CLI),
only controllers should be rewritten
The way of thinking about
Controllers
44/86
NodeJs example of a Service class
Base class (the simplest version)
46/86
47/86
Template method in base class
Guarantees that all procedures are kept:
● Data was validated
● “execute” will be called only after validation
● “execute” will receive only clean data
● Checks permissions before calling “execute”
● Throws exception in case of validation errors
Can do extra work like caching validator objects, etc.
“run” method
48/86
● Belongs to Model layer of MVC
● Contains application logic
● Does not trust any incoming params
● You should keep thin if possible
● Knows nothing about controllers/transport/UI.
● Use cases based API
● Knows about context (what user asks for data)
● Knows when and how to notify user (emails etc)
● Does coordination and security
● Coarse grained API (well suited for remote invocation)
The way of thinking about
Services
49/86
Never return objects directly
Whitelist every object property:
1. You know what you return (that no internal/secret data there)
2. Your API is stable
50/86
● DO NOT TRUST ANY USER INPUT! NEVER!!!
● Declarative validation
● Exclude all fields that do not have validation
rules described
● Returns understandable error codes (neither
error messages nor numeric codes)
● It should be clear for the service user what is
wrong with his data
Unified approach to validation
51/86
It should be clear where any code should be! Otherwise
you do not architecture.
One of the risks, than you can end up with
an “Anemic domain model”
(https://www.martinfowler.com/bliki/AnemicDomainModel.html)
If you have a large project, this can be a reason
of project failure as you will implicitly switch to
“transaction script” approach which is not well
suited for large applications.
Be aware of “Anemic domain
model” antipattern
52/86
ORM Sequelize
● Belongs to Model layer of MVC
● The core part of your application
● You have almost all of your business logic here (not
only database access)!!!
● Knows nothing about service layer and upper layers
● Responsible for data storing and data integrity
● Fine grained API (not suited for remote invocation)
The way of thinking about
Domain Model
54/86
● ES6 syntax
● Transactions
● Configuration
Sequelize
55/86
Sequelize ES6
(do not follow docs strictly)
57/86
58/86
Initialize once
59/86
Sequelize transactions
Continuation-local storage works like
thread-local storage in threaded programming,
but is based on chains of Node-style callbacks
instead of threads.
https://www.npmjs.com/package/cls-hooked
Transactions with CLS
(continuation local storage)
61/86
Transactions with CLS
(continuation local storage)
62/86
Sequelize config
Do not do this: violates
12 factors apps principles
64/86
Chatbot example in Perl6
https://github.com/koorchik/codegolf-telegram-bot/
Configs
How to work with configs
according to 12 factors?
“confme”
https://www.npmjs.com/package/confme
69/86
How to use config?
70/86
How to use config data for
Sequelize?
71/86
How to read config in migrations?
sequelize --config lib/config.js db:migrate --env db
72/86
How do we use “12 factors”
configs with next.js?
73/86
How do we use “12 factors”
configs with SPA?
Hack for Parcel (with webpack you just have “script” tag)
74/86
public/config.js and lib/config.js
74/86
“confme” demo
Docker
● How do new developers setup working environment?
● How to work with S3 (we do not use localstack)?
● How to work with emails?
● How to run the whole platform?
● How to do migrations?
● How to work with cron?
● Do I need pm2?
● How to build frontend in docker?
Questions
78/86
Demo
● Minio (vs localstack)
● Mailhog
● Adminer
Services that we use
80/86
User sessions
● Classical sessions or JWT?
● Which type of transport to use (Cookie, Query
params, Custom headers)?
● How to refresh JWT?
● CSRF protection?
● CORS issues?
● How to implement “Force logout”?
● Sensitive information
Questions to solve
82/86
● MonolithFirst by Martin Fowler
● Microservice Trade-Offs by Martin Fowler
● PresentationDomainDataLayering by Martin Fowler
● The Principles of Clean Architecture by Uncle Bob Martin
● The Clean Architecture by Robert Martin
● Microservice Architecture at Medium
● https://12factor.net/
Useful links
83/86
● Based on ideas of Clean Architecture
● Works with small and large projects
● Follows 12 factor app approach
● Modern JS (including ES6 for Sequelize)
● Supports both REST API and GraphQL
● Follows security best practices.
● Docker support
● Covered with tests
● Battle tested
● Built on top of express.js
● Users managment
NodeJs Starter App
84/86
https://github.com/WebbyLab/webbylab-
starter-app-for-nodejs
Telegram: @JABASCRIPT
85/86
Email
viktor@webbylab.com
Website
https://webbylab.com
@koorchik
@koorchik
My contacts
86/86

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Clean architecture
Clean architectureClean architecture
Clean architecture
 
A walkthrough of JavaScript ES6 features
A walkthrough of JavaScript ES6 featuresA walkthrough of JavaScript ES6 features
A walkthrough of JavaScript ES6 features
 
NYC Continuous Delivery Meetup - Introducing delta
NYC Continuous Delivery Meetup - Introducing deltaNYC Continuous Delivery Meetup - Introducing delta
NYC Continuous Delivery Meetup - Introducing delta
 
Introduction to K6
Introduction to K6Introduction to K6
Introduction to K6
 
Embracing Observability in CI/CD with OpenTelemetry
Embracing Observability in CI/CD with OpenTelemetryEmbracing Observability in CI/CD with OpenTelemetry
Embracing Observability in CI/CD with OpenTelemetry
 
CI back to basis
CI back to basisCI back to basis
CI back to basis
 
How to go about testing in React?
How to go about testing in React? How to go about testing in React?
How to go about testing in React?
 
Design Microservice Architectures the Right Way
Design Microservice Architectures the Right WayDesign Microservice Architectures the Right Way
Design Microservice Architectures the Right Way
 
Enter the Team City
Enter the Team CityEnter the Team City
Enter the Team City
 
Migration from AngularJS to Angular
Migration from AngularJS to AngularMigration from AngularJS to Angular
Migration from AngularJS to Angular
 
Testing Without a GUI Using TestComplete
 Testing Without a GUI Using TestComplete Testing Without a GUI Using TestComplete
Testing Without a GUI Using TestComplete
 
Alexey Kupriyanenko "Release Early, Often, Stable"
Alexey Kupriyanenko "Release Early, Often, Stable"Alexey Kupriyanenko "Release Early, Often, Stable"
Alexey Kupriyanenko "Release Early, Often, Stable"
 
vodQA Pune (2019) - Jenkins pipeline As code
vodQA Pune (2019) - Jenkins pipeline As codevodQA Pune (2019) - Jenkins pipeline As code
vodQA Pune (2019) - Jenkins pipeline As code
 
Trunk based development
Trunk based developmentTrunk based development
Trunk based development
 
Javascript Unit Testing Tools
Javascript Unit Testing ToolsJavascript Unit Testing Tools
Javascript Unit Testing Tools
 
TDD for APIs @ Europython 2015, Bilbao by Michael Kuehne
TDD for APIs @ Europython 2015, Bilbao by Michael KuehneTDD for APIs @ Europython 2015, Bilbao by Michael Kuehne
TDD for APIs @ Europython 2015, Bilbao by Michael Kuehne
 
Trunk based development for Beginners
Trunk based development for BeginnersTrunk based development for Beginners
Trunk based development for Beginners
 
Modern Tools for Building Progressive Web Apps
Modern Tools for Building Progressive Web AppsModern Tools for Building Progressive Web Apps
Modern Tools for Building Progressive Web Apps
 
Fault tolerance - look, it's simple!
Fault tolerance - look, it's simple!Fault tolerance - look, it's simple!
Fault tolerance - look, it's simple!
 
.NET Code Coverage for Continuous Integration using TeamCity and dotCover
.NET Code Coverage for Continuous Integrationusing TeamCity and dotCover.NET Code Coverage for Continuous Integrationusing TeamCity and dotCover
.NET Code Coverage for Continuous Integration using TeamCity and dotCover
 

Semelhante a 'Effective node.js development' by Viktor Turskyi at OdessaJS'2020

Network Automation Journey, A systems engineer NetOps perspective
Network Automation Journey, A systems engineer NetOps perspectiveNetwork Automation Journey, A systems engineer NetOps perspective
Network Automation Journey, A systems engineer NetOps perspective
Walid Shaari
 

Semelhante a 'Effective node.js development' by Viktor Turskyi at OdessaJS'2020 (20)

Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"
 
The working architecture of NodeJS applications, Виктор Турский
The working architecture of NodeJS applications, Виктор ТурскийThe working architecture of NodeJS applications, Виктор Турский
The working architecture of NodeJS applications, Виктор Турский
 
The working architecture of node js applications open tech week javascript ...
The working architecture of node js applications   open tech week javascript ...The working architecture of node js applications   open tech week javascript ...
The working architecture of node js applications open tech week javascript ...
 
The working architecture of NodeJs applications
The working architecture of NodeJs applicationsThe working architecture of NodeJs applications
The working architecture of NodeJs applications
 
"The working architecture of NodeJs applications" Viktor Turskyi
"The working architecture of NodeJs applications" Viktor Turskyi"The working architecture of NodeJs applications" Viktor Turskyi
"The working architecture of NodeJs applications" Viktor Turskyi
 
From class to architecture
From class to architectureFrom class to architecture
From class to architecture
 
Clean architecture
Clean architectureClean architecture
Clean architecture
 
Advanced web application architecture - Talk
Advanced web application architecture - TalkAdvanced web application architecture - Talk
Advanced web application architecture - Talk
 
Breaking down a monolith
Breaking down a monolithBreaking down a monolith
Breaking down a monolith
 
Joomla Code Quality Control and Automation Testing
Joomla Code Quality Control and Automation TestingJoomla Code Quality Control and Automation Testing
Joomla Code Quality Control and Automation Testing
 
The State of the Veil Framework
The State of the Veil FrameworkThe State of the Veil Framework
The State of the Veil Framework
 
DDD with Behat
DDD with BehatDDD with Behat
DDD with Behat
 
Keeping business logic out of your UIs
Keeping business logic out of your UIsKeeping business logic out of your UIs
Keeping business logic out of your UIs
 
Keeping code clean
Keeping code cleanKeeping code clean
Keeping code clean
 
Rapid app building with loopback framework
Rapid app building with loopback frameworkRapid app building with loopback framework
Rapid app building with loopback framework
 
Dev ops presentation
Dev ops presentationDev ops presentation
Dev ops presentation
 
Liferay portals in real projects
Liferay portals  in real projectsLiferay portals  in real projects
Liferay portals in real projects
 
Network Automation Journey, A systems engineer NetOps perspective
Network Automation Journey, A systems engineer NetOps perspectiveNetwork Automation Journey, A systems engineer NetOps perspective
Network Automation Journey, A systems engineer NetOps perspective
 
JavaScript for Enterprise Applications
JavaScript for Enterprise ApplicationsJavaScript for Enterprise Applications
JavaScript for Enterprise Applications
 
First Steps to DevOps
First Steps to DevOpsFirst Steps to DevOps
First Steps to DevOps
 

Mais de OdessaJS Conf

'GraphQL Schema Design' by Borys Mohyla. OdessaJS'2021
'GraphQL Schema Design' by Borys Mohyla. OdessaJS'2021'GraphQL Schema Design' by Borys Mohyla. OdessaJS'2021
'GraphQL Schema Design' by Borys Mohyla. OdessaJS'2021
OdessaJS Conf
 
'How i came up with my talk' by Yurii Artiukh. OdessaJS'2021
'How i came up with my talk' by Yurii Artiukh. OdessaJS'2021'How i came up with my talk' by Yurii Artiukh. OdessaJS'2021
'How i came up with my talk' by Yurii Artiukh. OdessaJS'2021
OdessaJS Conf
 
"Is there life in react without redux" by Babich Sergiy. OdessaJS'2021
"Is there life in react without redux" by Babich Sergiy. OdessaJS'2021"Is there life in react without redux" by Babich Sergiy. OdessaJS'2021
"Is there life in react without redux" by Babich Sergiy. OdessaJS'2021
OdessaJS Conf
 
Олексій Павленко. CONTRACT PROTECTION ON THE FRONTEND SIDE: HOW TO ORGANIZE R...
Олексій Павленко. CONTRACT PROTECTION ON THE FRONTEND SIDE: HOW TO ORGANIZE R...Олексій Павленко. CONTRACT PROTECTION ON THE FRONTEND SIDE: HOW TO ORGANIZE R...
Олексій Павленко. CONTRACT PROTECTION ON THE FRONTEND SIDE: HOW TO ORGANIZE R...
OdessaJS Conf
 
Олексій Гончар "Використання Electron в розробці корпоративної відео-мессeндж...
Олексій Гончар "Використання Electron в розробці корпоративної відео-мессeндж...Олексій Гончар "Використання Electron в розробці корпоративної відео-мессeндж...
Олексій Гончар "Використання Electron в розробці корпоративної відео-мессeндж...
OdessaJS Conf
 
Павло Галушко. GOOD CODE MYTHS. OdessaJS'2021
Павло Галушко. GOOD CODE MYTHS. OdessaJS'2021Павло Галушко. GOOD CODE MYTHS. OdessaJS'2021
Павло Галушко. GOOD CODE MYTHS. OdessaJS'2021
OdessaJS Conf
 
"NODEJS & GRAPHQL COOKBOOK. LET’S TALK ABOUT MICRO-SERVICES" by Антон Чередні...
"NODEJS & GRAPHQL COOKBOOK. LET’S TALK ABOUT MICRO-SERVICES" by Антон Чередні..."NODEJS & GRAPHQL COOKBOOK. LET’S TALK ABOUT MICRO-SERVICES" by Антон Чередні...
"NODEJS & GRAPHQL COOKBOOK. LET’S TALK ABOUT MICRO-SERVICES" by Антон Чередні...
OdessaJS Conf
 
'BUILDING ANGULAR APPS WITH NX' by Anastasia Necheporenko
'BUILDING ANGULAR APPS WITH NX' by Anastasia Necheporenko'BUILDING ANGULAR APPS WITH NX' by Anastasia Necheporenko
'BUILDING ANGULAR APPS WITH NX' by Anastasia Necheporenko
OdessaJS Conf
 
'IS THERE JAVASCRIPT ON SWAGGER PLUGINS?' by Dmytro Gusev
'IS THERE JAVASCRIPT ON SWAGGER PLUGINS?' by  Dmytro Gusev'IS THERE JAVASCRIPT ON SWAGGER PLUGINS?' by  Dmytro Gusev
'IS THERE JAVASCRIPT ON SWAGGER PLUGINS?' by Dmytro Gusev
OdessaJS Conf
 
'ETHEREUM SMART CONTRACTS ON JS' by Yaroslav Dvorovenko
'ETHEREUM SMART CONTRACTS ON JS' by Yaroslav Dvorovenko'ETHEREUM SMART CONTRACTS ON JS' by Yaroslav Dvorovenko
'ETHEREUM SMART CONTRACTS ON JS' by Yaroslav Dvorovenko
OdessaJS Conf
 
'GOLANG USAGE IN DEVELOPMENT OF NODE.JS APPLICATIONS (NODE.JS: IN GO WE TRUST...
'GOLANG USAGE IN DEVELOPMENT OF NODE.JS APPLICATIONS (NODE.JS: IN GO WE TRUST...'GOLANG USAGE IN DEVELOPMENT OF NODE.JS APPLICATIONS (NODE.JS: IN GO WE TRUST...
'GOLANG USAGE IN DEVELOPMENT OF NODE.JS APPLICATIONS (NODE.JS: IN GO WE TRUST...
OdessaJS Conf
 
'MICROFRONTENDS WITH REACT' by Liliia Karpenko
 'MICROFRONTENDS WITH REACT' by Liliia Karpenko 'MICROFRONTENDS WITH REACT' by Liliia Karpenko
'MICROFRONTENDS WITH REACT' by Liliia Karpenko
OdessaJS Conf
 

Mais de OdessaJS Conf (20)

'GraphQL Schema Design' by Borys Mohyla. OdessaJS'2021
'GraphQL Schema Design' by Borys Mohyla. OdessaJS'2021'GraphQL Schema Design' by Borys Mohyla. OdessaJS'2021
'GraphQL Schema Design' by Borys Mohyla. OdessaJS'2021
 
'How i came up with my talk' by Yurii Artiukh. OdessaJS'2021
'How i came up with my talk' by Yurii Artiukh. OdessaJS'2021'How i came up with my talk' by Yurii Artiukh. OdessaJS'2021
'How i came up with my talk' by Yurii Artiukh. OdessaJS'2021
 
"Is there life in react without redux" by Babich Sergiy. OdessaJS'2021
"Is there life in react without redux" by Babich Sergiy. OdessaJS'2021"Is there life in react without redux" by Babich Sergiy. OdessaJS'2021
"Is there life in react without redux" by Babich Sergiy. OdessaJS'2021
 
Олексій Павленко. CONTRACT PROTECTION ON THE FRONTEND SIDE: HOW TO ORGANIZE R...
Олексій Павленко. CONTRACT PROTECTION ON THE FRONTEND SIDE: HOW TO ORGANIZE R...Олексій Павленко. CONTRACT PROTECTION ON THE FRONTEND SIDE: HOW TO ORGANIZE R...
Олексій Павленко. CONTRACT PROTECTION ON THE FRONTEND SIDE: HOW TO ORGANIZE R...
 
Олексій Гончар "Використання Electron в розробці корпоративної відео-мессeндж...
Олексій Гончар "Використання Electron в розробці корпоративної відео-мессeндж...Олексій Гончар "Використання Electron в розробці корпоративної відео-мессeндж...
Олексій Гончар "Використання Electron в розробці корпоративної відео-мессeндж...
 
Павло Галушко. GOOD CODE MYTHS. OdessaJS'2021
Павло Галушко. GOOD CODE MYTHS. OdessaJS'2021Павло Галушко. GOOD CODE MYTHS. OdessaJS'2021
Павло Галушко. GOOD CODE MYTHS. OdessaJS'2021
 
"NODEJS & GRAPHQL COOKBOOK. LET’S TALK ABOUT MICRO-SERVICES" by Антон Чередні...
"NODEJS & GRAPHQL COOKBOOK. LET’S TALK ABOUT MICRO-SERVICES" by Антон Чередні..."NODEJS & GRAPHQL COOKBOOK. LET’S TALK ABOUT MICRO-SERVICES" by Антон Чередні...
"NODEJS & GRAPHQL COOKBOOK. LET’S TALK ABOUT MICRO-SERVICES" by Антон Чередні...
 
'BUILDING ANGULAR APPS WITH NX' by Anastasia Necheporenko
'BUILDING ANGULAR APPS WITH NX' by Anastasia Necheporenko'BUILDING ANGULAR APPS WITH NX' by Anastasia Necheporenko
'BUILDING ANGULAR APPS WITH NX' by Anastasia Necheporenko
 
'IS THERE JAVASCRIPT ON SWAGGER PLUGINS?' by Dmytro Gusev
'IS THERE JAVASCRIPT ON SWAGGER PLUGINS?' by  Dmytro Gusev'IS THERE JAVASCRIPT ON SWAGGER PLUGINS?' by  Dmytro Gusev
'IS THERE JAVASCRIPT ON SWAGGER PLUGINS?' by Dmytro Gusev
 
'ETHEREUM SMART CONTRACTS ON JS' by Yaroslav Dvorovenko
'ETHEREUM SMART CONTRACTS ON JS' by Yaroslav Dvorovenko'ETHEREUM SMART CONTRACTS ON JS' by Yaroslav Dvorovenko
'ETHEREUM SMART CONTRACTS ON JS' by Yaroslav Dvorovenko
 
'GOLANG USAGE IN DEVELOPMENT OF NODE.JS APPLICATIONS (NODE.JS: IN GO WE TRUST...
'GOLANG USAGE IN DEVELOPMENT OF NODE.JS APPLICATIONS (NODE.JS: IN GO WE TRUST...'GOLANG USAGE IN DEVELOPMENT OF NODE.JS APPLICATIONS (NODE.JS: IN GO WE TRUST...
'GOLANG USAGE IN DEVELOPMENT OF NODE.JS APPLICATIONS (NODE.JS: IN GO WE TRUST...
 
'MICROFRONTENDS WITH REACT' by Liliia Karpenko
 'MICROFRONTENDS WITH REACT' by Liliia Karpenko 'MICROFRONTENDS WITH REACT' by Liliia Karpenko
'MICROFRONTENDS WITH REACT' by Liliia Karpenko
 
'Web performance metrics' BY ROMAN SAVITSKYI at OdessaJS'2020
'Web performance metrics' BY ROMAN SAVITSKYI at OdessaJS'2020'Web performance metrics' BY ROMAN SAVITSKYI at OdessaJS'2020
'Web performance metrics' BY ROMAN SAVITSKYI at OdessaJS'2020
 
'STORY OF ANOTHER ANIMATION' by YURII ARTYUKH at OdessaJS'2020
'STORY OF ANOTHER ANIMATION' by  YURII ARTYUKH at OdessaJS'2020'STORY OF ANOTHER ANIMATION' by  YURII ARTYUKH at OdessaJS'2020
'STORY OF ANOTHER ANIMATION' by YURII ARTYUKH at OdessaJS'2020
 
'JavaScript was invented in Odessa' by DMITRIY GUSEV at OdessaJS'2020
'JavaScript was invented in Odessa' by DMITRIY GUSEV at OdessaJS'2020'JavaScript was invented in Odessa' by DMITRIY GUSEV at OdessaJS'2020
'JavaScript was invented in Odessa' by DMITRIY GUSEV at OdessaJS'2020
 
'Why svelte' by BORYS MOHYLA at OdessaJS'2020
'Why svelte' by BORYS MOHYLA at OdessaJS'2020'Why svelte' by BORYS MOHYLA at OdessaJS'2020
'Why svelte' by BORYS MOHYLA at OdessaJS'2020
 
'Tensorflow.js in real life' by Pavlo Galushko at OdessaJS'2020
'Tensorflow.js in real life' by Pavlo Galushko at OdessaJS'2020'Tensorflow.js in real life' by Pavlo Galushko at OdessaJS'2020
'Tensorflow.js in real life' by Pavlo Galushko at OdessaJS'2020
 
'React+d3=LOVE' by Illia Olenchenko at OdessaJS'2020
'React+d3=LOVE' by Illia Olenchenko at OdessaJS'2020'React+d3=LOVE' by Illia Olenchenko at OdessaJS'2020
'React+d3=LOVE' by Illia Olenchenko at OdessaJS'2020
 
'THE AGE OF DATA STREAMING' by DENIS BURYACHKOVSKY at OdessaJS'2020
'THE AGE OF DATA STREAMING' by DENIS BURYACHKOVSKY at OdessaJS'2020'THE AGE OF DATA STREAMING' by DENIS BURYACHKOVSKY at OdessaJS'2020
'THE AGE OF DATA STREAMING' by DENIS BURYACHKOVSKY at OdessaJS'2020
 
'Worker threads vs c++ addons' by Novokhatskyi Oleksii at OdessaJS'2020
'Worker threads vs c++ addons' by Novokhatskyi Oleksii at OdessaJS'2020'Worker threads vs c++ addons' by Novokhatskyi Oleksii at OdessaJS'2020
'Worker threads vs c++ addons' by Novokhatskyi Oleksii at OdessaJS'2020
 

Último

Último (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

'Effective node.js development' by Viktor Turskyi at OdessaJS'2020

  • 1. OdessaJS - 2020 Effective NodeJS Development Viktor Turskyi
  • 2. Viktor Turskyi ● CEO and principal software architect at WebbyLab ● Open source developer ● More than 15 years of experience ● Delivered more than 60 projects of different scale ● Did projects for 5 companies from Fortune 500 list 2/86
  • 3. Simple mental model for: ● Solution architecture ● Application architecture (https://www.youtube.com/watch?v=TjvIEgBCxZo) ● Development process ● Deployment process How to make development more effective? 3/86
  • 4. Solved most of the standard edge cases in starter-kit: ● Folders structure ● Configs ● Sessions ● Error handling ● Transactions ● Dependencies management (including 3rd party services) ● Tests etc How to make development more effective? 4/86
  • 6. Complex is easy. Simple is hard.
  • 7. ● Define standard technology stack ● Define standard architecture ● Define the most effective software development approaches ● Define the most effective deployment strategies ● Define the most effective way of production support ● Internal trainings Engineering productivity group 7/86
  • 8. ● NodeJS ● ReactJS ● React Native ● MySQL/Postgres ● S3 like object storage ● Docker Standard technology stack 8/86
  • 12. "If you cannot build a monolith what makes you think that you can build Distributed Microservices" Simon Brown
  • 13. ● High operational complexity (increases costs) ● Versions compatibility issues (harder to track all dependencies in consistent state, reduces iterations speed) ● Extremely hard to support transactions (risks of inconsistencies) ● Distribution issues (harder to program) ● Traceability issues (harder to debug) ● Technology diversity (mixing languages increases support costs, standardization issues, hiring issues etc) ● You need more experienced team (hiring issues) Microservices drawbacks 13/86
  • 15. What is the best architectural decision?
  • 16. “The job of architect is not to make decision, the job of the architect is to defer decisions as long as possible” “Good architecture maximizes number of decisions not made” Robert Martin https://www.youtube.com/watch?v=o_TH-Y78tt4
  • 17. ● But when your components are services with remote communications, then refactoring is much harder than with in-process libraries. ● Another issue is If the components do not compose cleanly, then all you are doing is shifting complexity from inside a component to the connections between components. Not just does this just move complexity around, it moves it to a place that's less explicit and harder to control. https://martinfowler.com/bliki/MonolithFirst.html Martin Fowler: 17/86
  • 18. So, we start with monolith in 90% of cases
  • 20. Usually it looks like 20/86
  • 25. ● Express ● Koa ● Sails ● Nest ● Feathers ● Derby ● Kraken ● Hapi etc NodeJs frameworks: 25/86
  • 27. Your application architecture should not depend on a web framework
  • 28. ● NodeJs: Express ● PHP: Slim3 ● Perl : Mojolicious Web frameworks we use 28/86
  • 29. “We use MVC why do we need another architecture?”
  • 31. Where to place this code? Model or Controller?
  • 32. “The M in MVC: Why Models are Misunderstood and Unappreciated” Pádraic Brady http://blog.astrumfutura.com/2008/12/the-m-in-mvc-w hy-models-are-misunderstood-and-unappreciated/ Fat Stupid Ugly Controllers 32/86
  • 33. Is Model (MVC) and Domain Model the same?
  • 34. ● Domain model ● Transaction script ● Table module ● Service layer Model (from MVC)/Domain Logic 34/86
  • 35. An object model of the domain that incorporates both behavior and data. (M. Fowler) Works well for medium and large applications. Domain model 35/86
  • 36. Organizes business logic by procedures where each procedure handles a single request from the presentation (M. Fowler). Works well for small projects. Transaction script 36/86
  • 37.
  • 39.
  • 40.
  • 41. How do we cook the service layer?
  • 42. Separate service class (implemented as command) for each endpoint 42/86
  • 43. Real code (with meta programming) 43/86
  • 44. ● Extremely thin layer ● Protects underneath layers from everything related to HTTP ● If you change JSON to XML (or even CLI), only controllers should be rewritten The way of thinking about Controllers 44/86
  • 45. NodeJs example of a Service class
  • 46. Base class (the simplest version) 46/86
  • 47. 47/86
  • 48. Template method in base class Guarantees that all procedures are kept: ● Data was validated ● “execute” will be called only after validation ● “execute” will receive only clean data ● Checks permissions before calling “execute” ● Throws exception in case of validation errors Can do extra work like caching validator objects, etc. “run” method 48/86
  • 49. ● Belongs to Model layer of MVC ● Contains application logic ● Does not trust any incoming params ● You should keep thin if possible ● Knows nothing about controllers/transport/UI. ● Use cases based API ● Knows about context (what user asks for data) ● Knows when and how to notify user (emails etc) ● Does coordination and security ● Coarse grained API (well suited for remote invocation) The way of thinking about Services 49/86
  • 50. Never return objects directly Whitelist every object property: 1. You know what you return (that no internal/secret data there) 2. Your API is stable 50/86
  • 51. ● DO NOT TRUST ANY USER INPUT! NEVER!!! ● Declarative validation ● Exclude all fields that do not have validation rules described ● Returns understandable error codes (neither error messages nor numeric codes) ● It should be clear for the service user what is wrong with his data Unified approach to validation 51/86
  • 52. It should be clear where any code should be! Otherwise you do not architecture. One of the risks, than you can end up with an “Anemic domain model” (https://www.martinfowler.com/bliki/AnemicDomainModel.html) If you have a large project, this can be a reason of project failure as you will implicitly switch to “transaction script” approach which is not well suited for large applications. Be aware of “Anemic domain model” antipattern 52/86
  • 54. ● Belongs to Model layer of MVC ● The core part of your application ● You have almost all of your business logic here (not only database access)!!! ● Knows nothing about service layer and upper layers ● Responsible for data storing and data integrity ● Fine grained API (not suited for remote invocation) The way of thinking about Domain Model 54/86
  • 55. ● ES6 syntax ● Transactions ● Configuration Sequelize 55/86
  • 56. Sequelize ES6 (do not follow docs strictly)
  • 57. 57/86
  • 58. 58/86
  • 61. Continuation-local storage works like thread-local storage in threaded programming, but is based on chains of Node-style callbacks instead of threads. https://www.npmjs.com/package/cls-hooked Transactions with CLS (continuation local storage) 61/86
  • 62. Transactions with CLS (continuation local storage) 62/86
  • 64. Do not do this: violates 12 factors apps principles 64/86
  • 65. Chatbot example in Perl6 https://github.com/koorchik/codegolf-telegram-bot/
  • 67. How to work with configs according to 12 factors?
  • 69. 69/86
  • 70. How to use config? 70/86
  • 71. How to use config data for Sequelize? 71/86
  • 72. How to read config in migrations? sequelize --config lib/config.js db:migrate --env db 72/86
  • 73. How do we use “12 factors” configs with next.js? 73/86
  • 74. How do we use “12 factors” configs with SPA? Hack for Parcel (with webpack you just have “script” tag) 74/86
  • 78. ● How do new developers setup working environment? ● How to work with S3 (we do not use localstack)? ● How to work with emails? ● How to run the whole platform? ● How to do migrations? ● How to work with cron? ● Do I need pm2? ● How to build frontend in docker? Questions 78/86
  • 79. Demo
  • 80. ● Minio (vs localstack) ● Mailhog ● Adminer Services that we use 80/86
  • 82. ● Classical sessions or JWT? ● Which type of transport to use (Cookie, Query params, Custom headers)? ● How to refresh JWT? ● CSRF protection? ● CORS issues? ● How to implement “Force logout”? ● Sensitive information Questions to solve 82/86
  • 83. ● MonolithFirst by Martin Fowler ● Microservice Trade-Offs by Martin Fowler ● PresentationDomainDataLayering by Martin Fowler ● The Principles of Clean Architecture by Uncle Bob Martin ● The Clean Architecture by Robert Martin ● Microservice Architecture at Medium ● https://12factor.net/ Useful links 83/86
  • 84. ● Based on ideas of Clean Architecture ● Works with small and large projects ● Follows 12 factor app approach ● Modern JS (including ES6 for Sequelize) ● Supports both REST API and GraphQL ● Follows security best practices. ● Docker support ● Covered with tests ● Battle tested ● Built on top of express.js ● Users managment NodeJs Starter App 84/86