Monolithic Architecture and its Pros n Cons
Microservice Architecture and its Pros n Cons
Service Discovery
Feature of Node.Js 10
HTTP2 and its feature
N-API
Building Rest API in Node.JS
Securing Rest API in Node.JS
Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2
1. Monolithic Architecture and its Pros n Cons
Microservice Architecture and its Pros n Cons
Service Discovery
Feature of Node.Js 10
HTTP2 and its feature
N-API
Building Rest API in Node.JS
Securing Rest API in Node.JS
Index
2. Monolithic Architecture
A monolithic architecture means that your app is written as one single unit of code whose
components are designed to work together, sharing the same memory space and resources.
Ex: JAR , WAR File which deployed as a single unit on application server
A microservice architecture means that your app is made up of lots of smaller, independent
services capable of running in their own memory space and scaling independently from each
other
1. Monolithic means composed all in one piece
2. In monolithic architecture, components of the program are interconnected and interdependent
rather than loosely coupled
3. If any program component must be updated, the whole application has to be rewritten
4. Not Modular : its a software application which is designed without modularity
5. Single-tiered software application
3. Disadvantages of Monolithic Arc.
1.Difficult to scale: scaling the app reqires running
multiple copies of entire app.
2. Long build/ test / release cycle
3. New releas takes months
4. Long time to add new feature
5. Lack of agility: Changes made to program can not
be done very rapidly
6. Adding new feature is complex as code grows
7. Small change made to a part of app requires entire
app to be rebuild and redeployed.
8. If a single component fails, it can cause the entire
application to fail which is unreliable
4. Disadvantages of Monolithic Arc.
9.Large and complex application: It becomes complex
to understand and modify such app and as a result
development slows down
10.Difficult to understand how to correctly implement
a change
11.Slow development: As the app and team grows
that app become difficult to understand and modify
because its huge in size and multiple team working on
it which makes developer less productive.
5. Microservice Architecure
Microservice architecture, is an approach to
application development in which a large application
is made up of samller independent services
Microservices run each application process as a
secvice
Communicate via well defined interface using
lightweight API
Each service performs a single function
Because they are independently run, each service
can be updated, deployed, and scaled to meet
demand for specific functions of an application.
6. Advanteges:
1. Single Deployment Unit
Since entire application is packaged as a single
unit, deployment process is relatively easy.
2.One Stop shop Codebase
navigating through the code base is easy
Proc and Cons
7. Advantages of Microservice
Agility – Changes in a particular micro service can
be done very rapidly and can be deployed very
quickly
Independent Development and Deployment
Reusable Code: Dividing software into small, well-
defined modules enables teams to use functions for
multiple purposes.
Maintainability: For each Service, a separate micro
service is created. Thus business code in a micro
service is very easy to understand.
8. Advantages of Microservice
Scalability: Individual components can scale as per
need, there is now no need to scale all components
together
Availability: Even if one service fails, other micro
services are highly available and the failed micro
service can be rectified very quickly
Fault Tolerance: Even if one micro service has some
faults with regards to say Database, thus there is a
very clear boundary defined with regards to any fault.
9. Advantages of Microservice
Do one thing well: Each microservice performs only
one task
Independent: (loosely coupled) components can be
changed, upgraded, or replaced independently
without affecting the functioning of other components.
Small and Focused: Each service performs a single
business function
Language Nuetral: Different microservices written in
different programming language as well as different
framework.
Rapid Build/Test/Realease cycle
10. Disadvantages of Microservice
Distributed Systems : Developing distributed systems
can be complex
Increased Resource use - All the independently
running components need their own runtime
containers with more memory and CPU.
Increase Network communication - Independently
running components interact with each other over a
network. Such systems require reliable and fast
network connections
Developer tools/IDEs don’t provide explicit support
for developing distributed applications.
11. Disadvantage of Microservice
Testing a microservices-based application can be
large. each dependent service needs to be confirmed
before you can start testing
Deploying microservices can be complex. They may
need coordination among multiple services.
Continuous deployment is difficult
Migration: The migration process from a monolithic
architecture to a microservices architecture requires
you to determine the right boundaries for
microservices
12. Disadvantage of Microservice
Developers must implement the inter-process
communication mechanism.
Increased memory consumption
Versions: Versioning for microservices can be
challenging
Multiple databases and transaction management
can be painful.
13. Q.How do we keep a track of all the
microservices?
Suppose we have a four different functions and they
might be running on four different servers.
By using SERVICE DISCOVERY TOOL we can
communicate with microservices.
Service discovery tools are a key value stores.
If one microservice fails then it does not affects other
microservice.
14. Q.How do we keep a track of all the
microservices?
These different microservices are in the separate
container and ready to join application and before
they work together they need to find one another.
they do this by using service discovery which creates
roadmap for this and many other microservices to
communicate.
When microservice found each other they
communicate through API.
15. Features of Node.js 10
N-API (Node.js API)
HTTP/2
openSSL 1.1.1
JavaScript language improvements
Error-handling improvements
Performance boosts via V8, including for the async
generator and array.
NPM v6
Better support of ES 6 modules
16. Features of Node.js 10
fs/promises API
fs/promises API gives us a set of alternative
asynchronous file system methods that return a
Promise object instead of using callbacks. We can
access this API through require('fs/promises')
17. N-API
Called as Next generation Node.js APIs for native
modules
Used for building native Addons
It is independent from the underlying JavaScript
runtime (ex V8) and is maintained as part of Node.js
itself
With N-API, native module developers can compile
their module once per platform and architecture, and
make it available for any version of Node.js that
implements N-API. This holds true even for versions
of Node.js that are built with a different VM, e.g.
Node-ChakraCore.
18. N-API
N-API enables different modules to work across
differnent version and flavours of node.js
without recompilation.
ChakraCore is a JavaScript engine developed
by Microsoft for its Microsoft Edge web browser
Chrome V8, is an open-source JavaScript
engine developed by for Google Chrome web
browsers.
19. Features of HTTP/2
Multiplexing : multiple req/res transaction occurs
over a single connection
Multiplexing the streams means that packages from
many streams are mixed over the same connection.
Single Connection :It has single connection with
multiple streams
Prioritization
Header Compression: H2 forces all HTTP headers
to be sent in a compressed format.
20. Features of HTTP/2
HPACK compression: Allows to compress http
headers
Server Push: Uses SERVER PUSH by which
necessary files like style.css, script.js will get stored
in cache
Servers can push web assets (CSS, JS, images)
before a browser knows it needs them which speeds
up page load times by reducing number of requests.
error in individual req/res transaction do not cause
socket connection to be destroyed
21. Features Of HTTP/2
Stream priority: Allows browsers to specify priority of
assets. For example, browser can request HTML
first to render it before any styles or JavaScript.
HTTP/2 Is Binary, Instead of Textual
Intelligent packet streaming management:
This results in reduced latency and accelerates
content download on modern web pages.
22. Building APIs in Node.js
Prefer using HTTP error codes:There are 75 status
codes and in most cases you can find a suitable one
Versioning: Any change made that is not backward
compatible, obviously will brake client applications.
APIs should built over HTTPS
23. Building APIs in Node.js
1. Use HTTP Methods & API Routes: POST, PUT,
GET, DELETE,PATCH . API routes should always
use nouns as resource identifiers.
2. Use HTTP Status Codes Correctly:
200, if everything was okay,
300, if the resource was moved,
500, if something went wrong on the API side
3. Pick the right framework for your Node.js REST
API: Express, Koa or Hapi, Restify
24. Building APIs in Node.js
Express, Koa or Hapi :used to create browser
applications, and as such, they support templating
and rendering
Restify: Used to build build REST services
4. Black-Box Test your Node.js REST APIs :
Black-box testing is a method of testing where the
functionality of an application is examined without the
knowledge of its internal structures or workings.
One of the modules that can help you with black-box
testing Node.js REST APIs is supertest.
25. Building APIs in Node.js
5. Embrace Rate Limiting: Rate limiting is used to
control how many requests a given consumer can
send to the API.
6. Create a Proper API Documentation: This is the
only one way you can describe it to clients or other
developers.
26. Secure REST API in Node.js
1. Cookie-based authentication: Server creates
active session in DB and place cookie with session
ID. Browser request protected resourse with cookie
and server verifies session ID against DB , if valid
it proceed.
2. Token Based Authentication:
a) JWT-Based, Stateless Authentication: Stateless
means server does not store any state about the
client session on the server side. session state
handled entirely by the client.
It cosnsist of three parts:
Header , Payload, Signature