3. The term microservices architecture refers
to a distributed computing architecture that is
built using a set of small, autonomous
services that act as a cohesive unit to solve a
business problem or problems
4. Advantages of Microservices
● Build highly scalable applications
● Build robust applications that withstand failures
● Better utilization of computing infrastructure
● Helps innovation with reduced time to market
● Build modular systems that are easy to manage and maintain
5. Characteristics of Microservices
● Independently deployable
● Design for failure
● Decentralized data management
● Domain driven design (finite scope per service)
● Agile development
● Container based deployments
6. Challenges of Microservices
● Inter-service communication
● Observability
● Error handling and troubleshooting
● Security
7. Inter-service communication for microservices
● Service Mesh based approach
○ Point to point communication
○ Become complex with the increase of microservices
○ Separate data plane and control plane
● Message Broker based approach
○ Fully decoupled communication
○ Complexity does not increase with the number of microservices
○ Subject based messaging
10. Why NATS?
● High performance:
○ NATS performs better than most of the existing message broker products, including
Kafka and RabbitMQ.
● Lightweight:
○ It does not need sophisticated hardware and complex deployment models to support
large message volumes.
● Simple to use:
○ It supplies a simple API to use the system. NATS has clients for over 30 programming
languages.
● At most once and at least once delivery:
○ Supports message guarantees required by applications.
● Support for event handling:
○ It can handle event streams with better performance.
11. NATS use cases
● Microservice-based applications:
○ Service mesh and inter-service messaging
● Event streaming applications:
○ Observability/analytics
○ Machine learning
○ Artificial intelligence
● Command and control-based systems:
○ Internet of Things (IoT) and edge computing
○ Telemetry/sensor data/command and control
● Augmenting or replacing legacy messaging systems
12. How NATS work?
● NATS uses a subject based messaging model with a fully decoupled publisher and a
subscriber
● Supports following message distribution mechanisms
○ Publish-Subscribe (topic based)
○ Request-Reply
○ Queue groups (load balancing)
● Messages are published on a subject and the consumers subscribe to the subject
● Wildcard subscriptions are allowed so that consumers can listen to messages from different
subjects and different publishers
13. NATS subject based messaging
● Supports wiretap messaging with
wildcard “>”
● Multi character wildcard can be
used to listen on a certain pattern of
subjects
● Specific subject name is used to
receive messages from specific
publishers
14. NATS request-reply messaging
● Publisher specifies a reply subject
(inbox)
● Subscriber respond through the
reply subject
● NATS can filter multiple responses
and send the first (fastest) response
15. NATS queue-groups messaging
● Publisher publishes on a subject. It
is not aware of the queue group
● Subscribers form a queue group by
specifying a common name for the
queue parameter
● Messages are delivered to the
subscribers in a load balanced
manner
16. NATS Clustering
● Helps scaling the NATS infrastructure according to the requirements of the application
● Clustering forms a fully connected server mesh. All nodes are aware of all the other nodes.
● Nodes are connected via sending simple messages (gossip) and does not require
pre-configuration of all the nodes
● Messages are replicated to one of the adjacent node so that node failure does not cause a
message loss
● Publisher and Subscriber can connect to different nodes (location transparency) to share
messages
● Most applications can be supported with a 3-node cluster
18. Microservices Inner-Outer Architecture
● Microservices does not exist in isolation.
● Inner Architecture deals with
○ Individual microservices
○ Inter-Service Communication
● Outer Architecture deals with
○ Integration with other parts of the enterprise platform
○ Governance of the microservices teams and processes
○ Shared services such as automation, infrastructure, observability
20. Building an Outpatient Department (OPD) Application
● A hospital OPD unit performs various tasks related to patient care
● Patient Registration
○ Admit new patients to the unit and register them on the system
● Patient Inspection
○ A physician inspect the patient and decide on the next steps
● Patient Treatment
○ Based on the inspection, nurses take care of the temporary treatments including
medication and doing various tests
● Patient Release
○ Once the temporary treatment is done, patient is discharged from the unit and send
back home or admit to a long term ward for further treatments
22. OPD Application Implementation
● Each microservice has its own database to store data related to that microservice
● Messages are used to share data between services
● Registration Service stores the patient details in the database and publish an event to the
inspection service with the patient ID and token number
● Inspection Service listens to the event and do the inspection and update its database with
inspection details. The required information is passed to the treatment service via an event.
● Treatment service receives the event and take actions accordingly and store the medication
schedules and test results in its database. Once the patient is ready to be released, it sends a
message via an event to the release service.
● Release service receives the event and discharge the patient and update its database.
23. Securing Microservices
● Security for external communications
○ Client applications consuming the services
○ Different types of clients including mobile, web and
standalone
○ Require advanced, standard security
○ OAuth 2.0 is becoming the de facto
○ API Gateways provides a standard mechanism to
implement security
● Security for internal communications
○ Services communicate with the NATS server
○ NATS support basic authentication, key based
authentication, JWT based authentication
○ Security can be implemented with TLS only since
consumers are internal (trusted subsystem)
24. Observability for Microservices with NATS
● Observability is a characteristic of the platform which defines how well the internal states of
a platform can be inferred from the knowledge of its external output
● It is a responsibility of each component in the platform to implement enough observability
through the external output such as
○ Log entries
○ Health check endpoints
○ Metrics endpoints
○ Application dashboards
● NATS supports observability through
○ Logging
○ Monitoring endpoints
26. Implementing Observability for Microservices with NATS
● Microservices implements /healthz and /metrics endpoints to provide application statistics
and status.
● Microservices publish logs to application specific log files
● NATS server has a separate log file and a set of endpoints to collect application statistics
● Prometheus collects application statistics from the endpoints of microservices and the NATS
server and publishes to Grafana
● Promtail and Loki collects log entries and publishes to Grafana for visualization
● Grafana is used to create dashboards for microservices and NATS server monitoring and
alert generation
27. Microservices and Integration Platforms
● Enterprise platforms consists of heterogeneous systems that needs to be integrated.
● Microservices based applications are one such component in the overall architecture.
● Integration Platforms plays a pivotal role in enterprise by doing
○ Application Integration
○ Data Integration
○ B2B Integration
○ API Management
● Microservices needs to co-exist with Integration Platforms
29. Microservices and Integration Platforms
● API-driven architecture is common within enterprise software platforms
● Services implemented at different layers based on their functionality and exposes APIs so
that subsequent layers can consume
● Microservices can implement services at one of these layers or at core business functionality
layer
● Microservices can integrate with other parts of the enterprise platform through the
integration platform since it supports the interoperability and acts as the anti-corruption
layer
30. Future of Microservices and NATS
● Trends/Developments in Microservices domain
○ Service Mesh is becoming popular though most people still failing to use it
○ Usage of Saga pattern to implement transactional microservices
○ Serverless platforms provides easier approach to build microservices based applications
● What’s new in NATS?
○ JetStream is becoming popular for streaming use cases of NATS which requires
advanced message delivery guarantees and persistence
○ NATS is used to build asynchronous logging frameworks and Service Mesh
31. Future of Microservices and NATS
● Trends/Developments in Microservices domain
○ Service Mesh is becoming popular though most people still failing to use it
○ Usage of Saga pattern to implement transactional microservices
○ Serverless platforms provides easier approach to build microservices based applications
● What’s new in NATS?
○ JetStream is becoming popular for streaming use cases of NATS which requires
advanced message delivery guarantees and persistence
○ NATS is used to build asynchronous logging frameworks and Service Mesh
32. Learn More
● The book that contains more
details can be found here
https://www.packtpub.com/product/d
esigning-microservices-platforms-wit
h-nats/9781801072212
33. Follow me
Chanaka Fernando, Associate
Director @ WSO2
Medium - https://medium.com/@chanakaudaya
Twitter - https://twitter.com/chanakaudaya
LinkedIn - https://www.linkedin.com/in/chanakaudaya
Github - https://github.com/chanakaudaya