SlideShare a Scribd company logo
1 of 63
Download to read offline
Key principles for a Node.js application in 2019
Designing Node.js applications for scalability, observability,
maintainability and K8S deployability
Olivier Loverde
CTO @Innovorder
PS: We’re HIRING! ✌
● Passionate about software engineering and
architecture
● Former Cedexis (sold >100M€ to Citrix)
● Currently CTO @Innovorder: foodtech startup
based in Paris who has raised 10M€+ (20 people in
engineering team)
● Hobbies include microelectronics & biohacking
About me
@loverdeolivier
Timeline
1. DDD scoping of our service
2. Software architecture (SOLID principles, Clean architecture)
3. Make our service observable (logging, monitoring, alerting)
4. Monitor key performance metrics and avoid bottleneck
5. Make it ready for Kubernetes (Stateless, Docker, Probes)
Key Principle #1
Define the role of our service using DDD
A way of identifying your domains
It provides in a couple of days a way to
collaboratively design an architecture :
● Domain events
● Domain definition
● Functional areas (i.e: Bounded Context)
● Relation between domains
Event Storming
1. Share knowledge and identify domain events
2. Think in terms of processes onward and backward
3. Identify domain boundaries
4. Classify domain type
5. Find domain relationship
Identify your domain using DDD
1. Core domain - Most of the focus should be spent here
Most important assets. These are the functional areas that make your competitive advantage.
2. Supportive domain
Too specific to buy, but not differentiating enough to build any competitive advantage.
3. Generic domain
They can be reused across many industries. It's not a good time investment to build your own.
Understand relations between your domains
Upstream VS downstream
Key Principle #1 - Summary
1. Use Event Storming for defining your domains
2. Classify your service into kind of domains (core, supportive or generic?)
3. Find the relationships between your domains
Key Principle #2
Skeleton for our service - Software Architecture
The SOLID principles
SOLID Principles
1. Single responsibility principle
2. Open / Closed principle : open for extension, closed for modification
3. Liskov substitution principle
4. Interface segregation principle
5. Dependency Injection Principle
SOLID Principles - Sorted by importance (from Robert C. Martin)
1. Single responsibility principle
2. Dependency Injection Principle
3. Open / Closed principle : open for extension, closed for modification
4. Liskov substitution principle
5. Interface segregation principle
SOLID principles in Typescript
SOLID - Single responsibility principle
A class should have only one responsibility.
SOLID - Open-closed principle
Software entities should be open for extension, but
closed for modification.
SOLID - Liskov Substitution principle
A subclass should behave in such a way that It will
NOT cause problems when used instead of the
superclass.
SOLID - Interface Segregation principle
Clients should not be forced to depend upon
interfaces that they don’t use.
You should have many small interfaces in your
software.
Dependency injection tool in Typescript
https://github.com/inversify/InversifyJS
Inversify.js
1. Allow JavaScript developers to write code that adheres to the SOLID principles.
2. Facilitate and encourage the adherence to the best OOP and IoC practices.
3. Add as little runtime overhead as possible.
Implementing the clean architecture
Robert C. Martin (Uncle Bob), 2012
What are we trying to achieve ?
● Avoiding module coupling
● Avoiding having pieces of business logic everywhere
● Doing tests properly
● Stop creating technical debt and having patches everywhere
● Create a maintainable system that grows nicely over the time
The dependency rule: This rule says that source code dependencies can only point inwards.
Robert C. Martin (Uncle Bob), 2012
OK - What’s the real implementation
looks like?
Folder structure
1. Stop using Controllers, Routes, Models folders
2. Use a layer-based folder structure :
○ src /
■ application/
● Use cases of your application.
■ domain/
● Models and repositories.
■ infrastructure/
● Communication with what is outside your application, like the database,
external services, etc.
● Interface such as http, amqp, etc.
Index.ts
1. Create an IoC container (using Inversify for instance)
2. Load each module into the container: application and infrastructure
3. Start your infrastructure (local connections, expose interfaces)
Clean architecture benefits
1. Respect SOLID principle
2. Each layer are fully testable
3. The dependency rule ensures a stable kernel
4. We keep the framework outside where they can do little harm
5. IoC reduces code coupling and increases maintainability
Key Principle #3
Observability
Node.js observability
1. We need to store, aggregate, process, graph and do alerts on our metrics
2. We need to be able to store custom metrics if needed
3. We need to store, view and query our logs in real-time
4. Metrics should be updated in real-time too
5. The system should be scalable and handle thousands of metrics and
services
© Matias
Node.js observability
1. You expose a /metrics endpoint inside your Node.js application
2. The endpoint should not be exposed to Internet (private network only)
3. You can use NPM packages such as “prom-client” for doing it:
Key Principle #4
Performance bottleneck analysis and tracking
Monitor key perf metrics and avoid bottleneck
● Finding memory leaks:
○ Single process can have a maximum heap of 1.5 GB
○ In the V8 runtime, full garbage collection stops the program execution.
● KPIs
○ Process Heap Size
○ Time consumed for garbage collection
○ Counters for full garbage collection cycles (All heap)
○ Counters for incremental garbage collection cycles (Subset of heap)
○ Released memory after garbage collection
Monitor key perf metrics and avoid bottleneck
● The Event Loop
○ We want to avoid “event loop lag”
● Common causes
○ Long-running synchronous processes
○ An incremental increase in tasks per loop
● KPIs
○ Slowest Event Handling (Max Latency)
○ Fastest Event Handling (Min Latency)
○ Average Event Loop Latency
Key Principle #5
Automated deployment with Kubernetes
Node.js in K8S
● Requirements:
○ Stateless application (i.e: no local state defined in our application)
○ Configuration management system and secret management (vault?)
○ A docker container encapsulate our application (i.e: no difference
between instances of our application)
○ Liveness and readiness probes
○ A working Kubernetes cluster (you can use Minikube for local dev)
Node.js in K8S - Docker part - Be aware of vulnerabilities!
Node.js in K8S - Docker part - Example
Node.js in K8S - Docker part
● Use node-alpine version : lean and secure root image for node
● Use LTS version for node
● Principle of privileges minimisation (no root user please)
Node.js in K8S - Probes part
● We must implement two dedicated endpoints:
○ /readiness
■ K8S uses this endpoint to know if service is ready to receive traffic
○ /liveness
■ K8S uses this endpoint to know if service needs to be restarted
● Theses endpoints are defined in the YAML manifest of the service
Example of liveness and readiness probes definition
Any code greater than or
equal to 200 and less than
400 indicates success.
Deployment & ConfigMap K8S YAML example
Thank you ! ✌

More Related Content

What's hot

Securing an NGINX deployment for K8s
Securing an NGINX deployment for K8sSecuring an NGINX deployment for K8s
Securing an NGINX deployment for K8sDevOps Indonesia
 
What's New in Kubernetes 1.18 Webinar Slides
What's New in Kubernetes 1.18 Webinar SlidesWhat's New in Kubernetes 1.18 Webinar Slides
What's New in Kubernetes 1.18 Webinar SlidesMirantis
 
DevSecOps Everything You Need To Know
DevSecOps Everything You Need To KnowDevSecOps Everything You Need To Know
DevSecOps Everything You Need To KnowCentextech
 
JSCONF 2018 - Baking security into DevOps - a tale of hunting down bugs befor...
JSCONF 2018 - Baking security into DevOps - a tale of hunting down bugs befor...JSCONF 2018 - Baking security into DevOps - a tale of hunting down bugs befor...
JSCONF 2018 - Baking security into DevOps - a tale of hunting down bugs befor...Wouter Bloeyaert
 
DevSecOps, The Good, Bad, and Ugly
DevSecOps, The Good, Bad, and UglyDevSecOps, The Good, Bad, and Ugly
DevSecOps, The Good, Bad, and Ugly4ndersonLin
 
SecurifyLabs & Tiki @ Countermeasure 2014
SecurifyLabs & Tiki @ Countermeasure 2014SecurifyLabs & Tiki @ Countermeasure 2014
SecurifyLabs & Tiki @ Countermeasure 2014securifylabs
 
DevOps Indonesia X Palo Alto and Dkatalis Roadshow to DevOpsDays Jakarta 2022
DevOps Indonesia X Palo Alto and Dkatalis Roadshow to DevOpsDays Jakarta 2022DevOps Indonesia X Palo Alto and Dkatalis Roadshow to DevOpsDays Jakarta 2022
DevOps Indonesia X Palo Alto and Dkatalis Roadshow to DevOpsDays Jakarta 2022DevOps Indonesia
 
Bio IT World 2015 - DevOps Security and Transparency
Bio IT World 2015 - DevOps Security and TransparencyBio IT World 2015 - DevOps Security and Transparency
Bio IT World 2015 - DevOps Security and TransparencyKevin Gilpin
 
2016-08-18 Red Hat Partner Security Update
2016-08-18 Red Hat Partner Security Update2016-08-18 Red Hat Partner Security Update
2016-08-18 Red Hat Partner Security UpdateShawn Wells
 
Continuous Security for GitOps
Continuous Security for GitOpsContinuous Security for GitOps
Continuous Security for GitOpsWeaveworks
 
Devcon3 : iExec Allowing Scalable, Efficient, and Virtualized Off-chain Execu...
Devcon3 : iExec Allowing Scalable, Efficient, and Virtualized Off-chain Execu...Devcon3 : iExec Allowing Scalable, Efficient, and Virtualized Off-chain Execu...
Devcon3 : iExec Allowing Scalable, Efficient, and Virtualized Off-chain Execu...Gilles Fedak
 
DevSecOps Implementation Journey
DevSecOps Implementation JourneyDevSecOps Implementation Journey
DevSecOps Implementation JourneyDevOps Indonesia
 
Dev secops security and compliance at the speed of continuous delivery - owasp
Dev secops  security and compliance at the speed of continuous delivery - owaspDev secops  security and compliance at the speed of continuous delivery - owasp
Dev secops security and compliance at the speed of continuous delivery - owaspDag Rowe
 
AWS live hack: Docker + Snyk Container on AWS
AWS live hack: Docker + Snyk Container on AWSAWS live hack: Docker + Snyk Container on AWS
AWS live hack: Docker + Snyk Container on AWSEric Smalling
 
How to build a self-documenting application
How to build a self-documenting applicationHow to build a self-documenting application
How to build a self-documenting applicationconjur_inc
 
[muCon2017]DevSecOps: How to Continuously Integrate Security into DevOps
[muCon2017]DevSecOps: How to Continuously Integrate Security into DevOps[muCon2017]DevSecOps: How to Continuously Integrate Security into DevOps
[muCon2017]DevSecOps: How to Continuously Integrate Security into DevOpsDaniel Oh
 
C++ Webinar "Why Should You Learn C++ in 2021-22?"
C++ Webinar "Why Should You Learn C++ in 2021-22?"C++ Webinar "Why Should You Learn C++ in 2021-22?"
C++ Webinar "Why Should You Learn C++ in 2021-22?"GlobalLogic Ukraine
 
Building A Self-Documenting Application: A Study in Chef and Compliance
Building A Self-Documenting Application: A Study in Chef and ComplianceBuilding A Self-Documenting Application: A Study in Chef and Compliance
Building A Self-Documenting Application: A Study in Chef and ComplianceKevin Gilpin
 

What's hot (20)

Securing an NGINX deployment for K8s
Securing an NGINX deployment for K8sSecuring an NGINX deployment for K8s
Securing an NGINX deployment for K8s
 
What's New in Kubernetes 1.18 Webinar Slides
What's New in Kubernetes 1.18 Webinar SlidesWhat's New in Kubernetes 1.18 Webinar Slides
What's New in Kubernetes 1.18 Webinar Slides
 
DevSecOps Everything You Need To Know
DevSecOps Everything You Need To KnowDevSecOps Everything You Need To Know
DevSecOps Everything You Need To Know
 
JSCONF 2018 - Baking security into DevOps - a tale of hunting down bugs befor...
JSCONF 2018 - Baking security into DevOps - a tale of hunting down bugs befor...JSCONF 2018 - Baking security into DevOps - a tale of hunting down bugs befor...
JSCONF 2018 - Baking security into DevOps - a tale of hunting down bugs befor...
 
Talk DevSecOps to me
Talk DevSecOps to meTalk DevSecOps to me
Talk DevSecOps to me
 
DevSecOps, The Good, Bad, and Ugly
DevSecOps, The Good, Bad, and UglyDevSecOps, The Good, Bad, and Ugly
DevSecOps, The Good, Bad, and Ugly
 
DevOps at FSOFT as BOI | Nguyễn Hoài Nam, Vũ Xuân Lộc
DevOps at FSOFT as BOI | Nguyễn Hoài Nam, Vũ Xuân LộcDevOps at FSOFT as BOI | Nguyễn Hoài Nam, Vũ Xuân Lộc
DevOps at FSOFT as BOI | Nguyễn Hoài Nam, Vũ Xuân Lộc
 
SecurifyLabs & Tiki @ Countermeasure 2014
SecurifyLabs & Tiki @ Countermeasure 2014SecurifyLabs & Tiki @ Countermeasure 2014
SecurifyLabs & Tiki @ Countermeasure 2014
 
DevOps Indonesia X Palo Alto and Dkatalis Roadshow to DevOpsDays Jakarta 2022
DevOps Indonesia X Palo Alto and Dkatalis Roadshow to DevOpsDays Jakarta 2022DevOps Indonesia X Palo Alto and Dkatalis Roadshow to DevOpsDays Jakarta 2022
DevOps Indonesia X Palo Alto and Dkatalis Roadshow to DevOpsDays Jakarta 2022
 
Bio IT World 2015 - DevOps Security and Transparency
Bio IT World 2015 - DevOps Security and TransparencyBio IT World 2015 - DevOps Security and Transparency
Bio IT World 2015 - DevOps Security and Transparency
 
2016-08-18 Red Hat Partner Security Update
2016-08-18 Red Hat Partner Security Update2016-08-18 Red Hat Partner Security Update
2016-08-18 Red Hat Partner Security Update
 
Continuous Security for GitOps
Continuous Security for GitOpsContinuous Security for GitOps
Continuous Security for GitOps
 
Devcon3 : iExec Allowing Scalable, Efficient, and Virtualized Off-chain Execu...
Devcon3 : iExec Allowing Scalable, Efficient, and Virtualized Off-chain Execu...Devcon3 : iExec Allowing Scalable, Efficient, and Virtualized Off-chain Execu...
Devcon3 : iExec Allowing Scalable, Efficient, and Virtualized Off-chain Execu...
 
DevSecOps Implementation Journey
DevSecOps Implementation JourneyDevSecOps Implementation Journey
DevSecOps Implementation Journey
 
Dev secops security and compliance at the speed of continuous delivery - owasp
Dev secops  security and compliance at the speed of continuous delivery - owaspDev secops  security and compliance at the speed of continuous delivery - owasp
Dev secops security and compliance at the speed of continuous delivery - owasp
 
AWS live hack: Docker + Snyk Container on AWS
AWS live hack: Docker + Snyk Container on AWSAWS live hack: Docker + Snyk Container on AWS
AWS live hack: Docker + Snyk Container on AWS
 
How to build a self-documenting application
How to build a self-documenting applicationHow to build a self-documenting application
How to build a self-documenting application
 
[muCon2017]DevSecOps: How to Continuously Integrate Security into DevOps
[muCon2017]DevSecOps: How to Continuously Integrate Security into DevOps[muCon2017]DevSecOps: How to Continuously Integrate Security into DevOps
[muCon2017]DevSecOps: How to Continuously Integrate Security into DevOps
 
C++ Webinar "Why Should You Learn C++ in 2021-22?"
C++ Webinar "Why Should You Learn C++ in 2021-22?"C++ Webinar "Why Should You Learn C++ in 2021-22?"
C++ Webinar "Why Should You Learn C++ in 2021-22?"
 
Building A Self-Documenting Application: A Study in Chef and Compliance
Building A Self-Documenting Application: A Study in Chef and ComplianceBuilding A Self-Documenting Application: A Study in Chef and Compliance
Building A Self-Documenting Application: A Study in Chef and Compliance
 

Similar to Node.js Service - Best practices in 2019

Montreal Kubernetes Meetup: Developer-first workflows (for microservices) on ...
Montreal Kubernetes Meetup: Developer-first workflows (for microservices) on ...Montreal Kubernetes Meetup: Developer-first workflows (for microservices) on ...
Montreal Kubernetes Meetup: Developer-first workflows (for microservices) on ...Ambassador Labs
 
Micro Front-End & Microservices - Plansoft
Micro Front-End & Microservices - PlansoftMicro Front-End & Microservices - Plansoft
Micro Front-End & Microservices - PlansoftMiki Lombardi
 
From CoreOS to Kubernetes and Concourse CI
From CoreOS to Kubernetes and Concourse CIFrom CoreOS to Kubernetes and Concourse CI
From CoreOS to Kubernetes and Concourse CIDenis Izmaylov
 
Docker Birthday #5 Meetup Cluj - Presentation
Docker Birthday #5 Meetup Cluj - PresentationDocker Birthday #5 Meetup Cluj - Presentation
Docker Birthday #5 Meetup Cluj - PresentationAlex Vranceanu
 
Reactive Micro Services with Java seminar
Reactive Micro Services with Java seminarReactive Micro Services with Java seminar
Reactive Micro Services with Java seminarGal Marder
 
Docker Bday #5, SF Edition: Introduction to Docker
Docker Bday #5, SF Edition: Introduction to DockerDocker Bday #5, SF Edition: Introduction to Docker
Docker Bday #5, SF Edition: Introduction to DockerDocker, Inc.
 
Migrating from oracle soa suite to microservices on kubernetes
Migrating from oracle soa suite to microservices on kubernetesMigrating from oracle soa suite to microservices on kubernetes
Migrating from oracle soa suite to microservices on kubernetesKonveyor Community
 
Summit 16: NetIDE: Integrating and Orchestrating SDN Controllers
Summit 16: NetIDE: Integrating and Orchestrating SDN ControllersSummit 16: NetIDE: Integrating and Orchestrating SDN Controllers
Summit 16: NetIDE: Integrating and Orchestrating SDN ControllersOPNFV
 
Application Centric Microservices from Redhat Summit 2015
Application Centric Microservices from Redhat Summit 2015Application Centric Microservices from Redhat Summit 2015
Application Centric Microservices from Redhat Summit 2015Ken Owens
 
Microservices & Serverless Architecture Principles Applied - Cisco Live Orlan...
Microservices & Serverless Architecture Principles Applied - Cisco Live Orlan...Microservices & Serverless Architecture Principles Applied - Cisco Live Orlan...
Microservices & Serverless Architecture Principles Applied - Cisco Live Orlan...Cisco DevNet
 
The NRB Group mainframe day 2021 - Containerisation on Z - Paul Pilotto - Seb...
The NRB Group mainframe day 2021 - Containerisation on Z - Paul Pilotto - Seb...The NRB Group mainframe day 2021 - Containerisation on Z - Paul Pilotto - Seb...
The NRB Group mainframe day 2021 - Containerisation on Z - Paul Pilotto - Seb...NRB
 
Microservice Workshop Hands On
Microservice Workshop Hands On Microservice Workshop Hands On
Microservice Workshop Hands On Ram G Suri
 
Kubernetes, Toolbox to fail or succeed for beginners - Demi Ben-Ari, VP R&D @...
Kubernetes, Toolbox to fail or succeed for beginners - Demi Ben-Ari, VP R&D @...Kubernetes, Toolbox to fail or succeed for beginners - Demi Ben-Ari, VP R&D @...
Kubernetes, Toolbox to fail or succeed for beginners - Demi Ben-Ari, VP R&D @...Demi Ben-Ari
 
Technology insights: Decision Science Platform
Technology insights: Decision Science PlatformTechnology insights: Decision Science Platform
Technology insights: Decision Science PlatformDecision Science Community
 
Design Like a Pro: Planning Enterprise Solutions
Design Like a Pro: Planning Enterprise SolutionsDesign Like a Pro: Planning Enterprise Solutions
Design Like a Pro: Planning Enterprise SolutionsInductive Automation
 
Design Like a Pro: Planning Enterprise Solutions
Design Like a Pro: Planning Enterprise SolutionsDesign Like a Pro: Planning Enterprise Solutions
Design Like a Pro: Planning Enterprise SolutionsInductive Automation
 
A Summary about Hykes' Keynote on Dockercon 2015
A Summary about Hykes' Keynote on Dockercon 2015A Summary about Hykes' Keynote on Dockercon 2015
A Summary about Hykes' Keynote on Dockercon 2015Henry Huang
 
Securing the container DevOps pipeline by William Henry
Securing the container DevOps pipeline by William HenrySecuring the container DevOps pipeline by William Henry
Securing the container DevOps pipeline by William HenryDevSecCon
 
Intro to OpenShift, MongoDB Atlas & Live Demo
Intro to OpenShift, MongoDB Atlas & Live DemoIntro to OpenShift, MongoDB Atlas & Live Demo
Intro to OpenShift, MongoDB Atlas & Live DemoMongoDB
 
Agile integration: Decomposing the monolith
Agile integration: Decomposing the monolithAgile integration: Decomposing the monolith
Agile integration: Decomposing the monolithJudy Breedlove
 

Similar to Node.js Service - Best practices in 2019 (20)

Montreal Kubernetes Meetup: Developer-first workflows (for microservices) on ...
Montreal Kubernetes Meetup: Developer-first workflows (for microservices) on ...Montreal Kubernetes Meetup: Developer-first workflows (for microservices) on ...
Montreal Kubernetes Meetup: Developer-first workflows (for microservices) on ...
 
Micro Front-End & Microservices - Plansoft
Micro Front-End & Microservices - PlansoftMicro Front-End & Microservices - Plansoft
Micro Front-End & Microservices - Plansoft
 
From CoreOS to Kubernetes and Concourse CI
From CoreOS to Kubernetes and Concourse CIFrom CoreOS to Kubernetes and Concourse CI
From CoreOS to Kubernetes and Concourse CI
 
Docker Birthday #5 Meetup Cluj - Presentation
Docker Birthday #5 Meetup Cluj - PresentationDocker Birthday #5 Meetup Cluj - Presentation
Docker Birthday #5 Meetup Cluj - Presentation
 
Reactive Micro Services with Java seminar
Reactive Micro Services with Java seminarReactive Micro Services with Java seminar
Reactive Micro Services with Java seminar
 
Docker Bday #5, SF Edition: Introduction to Docker
Docker Bday #5, SF Edition: Introduction to DockerDocker Bday #5, SF Edition: Introduction to Docker
Docker Bday #5, SF Edition: Introduction to Docker
 
Migrating from oracle soa suite to microservices on kubernetes
Migrating from oracle soa suite to microservices on kubernetesMigrating from oracle soa suite to microservices on kubernetes
Migrating from oracle soa suite to microservices on kubernetes
 
Summit 16: NetIDE: Integrating and Orchestrating SDN Controllers
Summit 16: NetIDE: Integrating and Orchestrating SDN ControllersSummit 16: NetIDE: Integrating and Orchestrating SDN Controllers
Summit 16: NetIDE: Integrating and Orchestrating SDN Controllers
 
Application Centric Microservices from Redhat Summit 2015
Application Centric Microservices from Redhat Summit 2015Application Centric Microservices from Redhat Summit 2015
Application Centric Microservices from Redhat Summit 2015
 
Microservices & Serverless Architecture Principles Applied - Cisco Live Orlan...
Microservices & Serverless Architecture Principles Applied - Cisco Live Orlan...Microservices & Serverless Architecture Principles Applied - Cisco Live Orlan...
Microservices & Serverless Architecture Principles Applied - Cisco Live Orlan...
 
The NRB Group mainframe day 2021 - Containerisation on Z - Paul Pilotto - Seb...
The NRB Group mainframe day 2021 - Containerisation on Z - Paul Pilotto - Seb...The NRB Group mainframe day 2021 - Containerisation on Z - Paul Pilotto - Seb...
The NRB Group mainframe day 2021 - Containerisation on Z - Paul Pilotto - Seb...
 
Microservice Workshop Hands On
Microservice Workshop Hands On Microservice Workshop Hands On
Microservice Workshop Hands On
 
Kubernetes, Toolbox to fail or succeed for beginners - Demi Ben-Ari, VP R&D @...
Kubernetes, Toolbox to fail or succeed for beginners - Demi Ben-Ari, VP R&D @...Kubernetes, Toolbox to fail or succeed for beginners - Demi Ben-Ari, VP R&D @...
Kubernetes, Toolbox to fail or succeed for beginners - Demi Ben-Ari, VP R&D @...
 
Technology insights: Decision Science Platform
Technology insights: Decision Science PlatformTechnology insights: Decision Science Platform
Technology insights: Decision Science Platform
 
Design Like a Pro: Planning Enterprise Solutions
Design Like a Pro: Planning Enterprise SolutionsDesign Like a Pro: Planning Enterprise Solutions
Design Like a Pro: Planning Enterprise Solutions
 
Design Like a Pro: Planning Enterprise Solutions
Design Like a Pro: Planning Enterprise SolutionsDesign Like a Pro: Planning Enterprise Solutions
Design Like a Pro: Planning Enterprise Solutions
 
A Summary about Hykes' Keynote on Dockercon 2015
A Summary about Hykes' Keynote on Dockercon 2015A Summary about Hykes' Keynote on Dockercon 2015
A Summary about Hykes' Keynote on Dockercon 2015
 
Securing the container DevOps pipeline by William Henry
Securing the container DevOps pipeline by William HenrySecuring the container DevOps pipeline by William Henry
Securing the container DevOps pipeline by William Henry
 
Intro to OpenShift, MongoDB Atlas & Live Demo
Intro to OpenShift, MongoDB Atlas & Live DemoIntro to OpenShift, MongoDB Atlas & Live Demo
Intro to OpenShift, MongoDB Atlas & Live Demo
 
Agile integration: Decomposing the monolith
Agile integration: Decomposing the monolithAgile integration: Decomposing the monolith
Agile integration: Decomposing the monolith
 

Recently uploaded

High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 

Recently uploaded (20)

High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 

Node.js Service - Best practices in 2019

  • 1. Key principles for a Node.js application in 2019 Designing Node.js applications for scalability, observability, maintainability and K8S deployability Olivier Loverde CTO @Innovorder PS: We’re HIRING! ✌
  • 2. ● Passionate about software engineering and architecture ● Former Cedexis (sold >100M€ to Citrix) ● Currently CTO @Innovorder: foodtech startup based in Paris who has raised 10M€+ (20 people in engineering team) ● Hobbies include microelectronics & biohacking About me @loverdeolivier
  • 3. Timeline 1. DDD scoping of our service 2. Software architecture (SOLID principles, Clean architecture) 3. Make our service observable (logging, monitoring, alerting) 4. Monitor key performance metrics and avoid bottleneck 5. Make it ready for Kubernetes (Stateless, Docker, Probes)
  • 4. Key Principle #1 Define the role of our service using DDD
  • 5. A way of identifying your domains It provides in a couple of days a way to collaboratively design an architecture : ● Domain events ● Domain definition ● Functional areas (i.e: Bounded Context) ● Relation between domains
  • 6.
  • 7. Event Storming 1. Share knowledge and identify domain events 2. Think in terms of processes onward and backward 3. Identify domain boundaries 4. Classify domain type 5. Find domain relationship
  • 8. Identify your domain using DDD 1. Core domain - Most of the focus should be spent here Most important assets. These are the functional areas that make your competitive advantage. 2. Supportive domain Too specific to buy, but not differentiating enough to build any competitive advantage. 3. Generic domain They can be reused across many industries. It's not a good time investment to build your own.
  • 11. Key Principle #1 - Summary 1. Use Event Storming for defining your domains 2. Classify your service into kind of domains (core, supportive or generic?) 3. Find the relationships between your domains
  • 12. Key Principle #2 Skeleton for our service - Software Architecture
  • 14. SOLID Principles 1. Single responsibility principle 2. Open / Closed principle : open for extension, closed for modification 3. Liskov substitution principle 4. Interface segregation principle 5. Dependency Injection Principle
  • 15. SOLID Principles - Sorted by importance (from Robert C. Martin) 1. Single responsibility principle 2. Dependency Injection Principle 3. Open / Closed principle : open for extension, closed for modification 4. Liskov substitution principle 5. Interface segregation principle
  • 16. SOLID principles in Typescript
  • 17.
  • 18. SOLID - Single responsibility principle A class should have only one responsibility.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25. SOLID - Open-closed principle Software entities should be open for extension, but closed for modification.
  • 26.
  • 27.
  • 28.
  • 29. SOLID - Liskov Substitution principle A subclass should behave in such a way that It will NOT cause problems when used instead of the superclass.
  • 30.
  • 31.
  • 32. SOLID - Interface Segregation principle Clients should not be forced to depend upon interfaces that they don’t use. You should have many small interfaces in your software.
  • 33.
  • 34.
  • 35. Dependency injection tool in Typescript
  • 37. Inversify.js 1. Allow JavaScript developers to write code that adheres to the SOLID principles. 2. Facilitate and encourage the adherence to the best OOP and IoC practices. 3. Add as little runtime overhead as possible.
  • 38. Implementing the clean architecture
  • 39.
  • 40. Robert C. Martin (Uncle Bob), 2012
  • 41. What are we trying to achieve ? ● Avoiding module coupling ● Avoiding having pieces of business logic everywhere ● Doing tests properly ● Stop creating technical debt and having patches everywhere ● Create a maintainable system that grows nicely over the time
  • 42. The dependency rule: This rule says that source code dependencies can only point inwards. Robert C. Martin (Uncle Bob), 2012
  • 43. OK - What’s the real implementation looks like?
  • 44. Folder structure 1. Stop using Controllers, Routes, Models folders 2. Use a layer-based folder structure : ○ src / ■ application/ ● Use cases of your application. ■ domain/ ● Models and repositories. ■ infrastructure/ ● Communication with what is outside your application, like the database, external services, etc. ● Interface such as http, amqp, etc.
  • 45. Index.ts 1. Create an IoC container (using Inversify for instance) 2. Load each module into the container: application and infrastructure 3. Start your infrastructure (local connections, expose interfaces)
  • 46. Clean architecture benefits 1. Respect SOLID principle 2. Each layer are fully testable 3. The dependency rule ensures a stable kernel 4. We keep the framework outside where they can do little harm 5. IoC reduces code coupling and increases maintainability
  • 48. Node.js observability 1. We need to store, aggregate, process, graph and do alerts on our metrics 2. We need to be able to store custom metrics if needed 3. We need to store, view and query our logs in real-time 4. Metrics should be updated in real-time too 5. The system should be scalable and handle thousands of metrics and services
  • 50. Node.js observability 1. You expose a /metrics endpoint inside your Node.js application 2. The endpoint should not be exposed to Internet (private network only) 3. You can use NPM packages such as “prom-client” for doing it:
  • 51. Key Principle #4 Performance bottleneck analysis and tracking
  • 52. Monitor key perf metrics and avoid bottleneck ● Finding memory leaks: ○ Single process can have a maximum heap of 1.5 GB ○ In the V8 runtime, full garbage collection stops the program execution. ● KPIs ○ Process Heap Size ○ Time consumed for garbage collection ○ Counters for full garbage collection cycles (All heap) ○ Counters for incremental garbage collection cycles (Subset of heap) ○ Released memory after garbage collection
  • 53. Monitor key perf metrics and avoid bottleneck ● The Event Loop ○ We want to avoid “event loop lag” ● Common causes ○ Long-running synchronous processes ○ An incremental increase in tasks per loop ● KPIs ○ Slowest Event Handling (Max Latency) ○ Fastest Event Handling (Min Latency) ○ Average Event Loop Latency
  • 54. Key Principle #5 Automated deployment with Kubernetes
  • 55. Node.js in K8S ● Requirements: ○ Stateless application (i.e: no local state defined in our application) ○ Configuration management system and secret management (vault?) ○ A docker container encapsulate our application (i.e: no difference between instances of our application) ○ Liveness and readiness probes ○ A working Kubernetes cluster (you can use Minikube for local dev)
  • 56. Node.js in K8S - Docker part - Be aware of vulnerabilities!
  • 57. Node.js in K8S - Docker part - Example
  • 58. Node.js in K8S - Docker part ● Use node-alpine version : lean and secure root image for node ● Use LTS version for node ● Principle of privileges minimisation (no root user please)
  • 59. Node.js in K8S - Probes part ● We must implement two dedicated endpoints: ○ /readiness ■ K8S uses this endpoint to know if service is ready to receive traffic ○ /liveness ■ K8S uses this endpoint to know if service needs to be restarted ● Theses endpoints are defined in the YAML manifest of the service
  • 60. Example of liveness and readiness probes definition Any code greater than or equal to 200 and less than 400 indicates success.
  • 61. Deployment & ConfigMap K8S YAML example
  • 62.
  • 63. Thank you !