How many of you have used messaging system?
How many of you know about NATS ?
Pulsar ?
Red Panda ?
Kafka ?
ActiveMQ ? RabittMQ ?
Siddharth Jain
Senior Staff at Nutanix
Sourabh Agrawal
MTS-4 at Nutanix
Ø Distributed System Enthusiast
Ø SME For Pulsar & NATS
Ø Decade of experience with apps,
infra & cloud
Ø Software architect with two decades of
experience
Ø Excited about:
ü Distributed Systems
ü Security
ü Non-functional aspects of systems
linkedin.com/in/siddharth-jain-4725bb19/
linkedin.com/in/sourabhaggrawal/
slideshare.net/souravagrawal35
https://github.com/souravagrawal
What we love about NATS ?
• Developed in GO
• Configure only what you need
• Cross cloud, cross geo and extended to edge
• Single digit millisecond latency
• Only one binary to run
• Active Community on
slack
• Open-Sourced
Why should you care ?
• CNCF Project
• Over 40 client language implementations
• Github: 11.2K Stars, 1.1K forks
• 10+Years of consistent development
What is NATS ?
• NATS is “Open Sourced, Apache Licensed” lightweight and high-
performance messaging system designed for building distributed and scalable
applications. NATS simple ecosystem is what makes it stand apart from
other. It’s a client-server system with a massive performant and horizontally
scalable server component.
cclient
client
server
Core NATS
• NATS started its journey with Core NATS, where you can publish/subscribe
to a subject, but the messages are “not persisted” and only active subscriber
will receive the message. In case if consumer is not active it loses the
message, so NATS core follows “At most once delivery”.
Core NATS
Core NATS
Load Distribution with
Queue Groups
Jetstream
PERSISTENT
MESSAGING
DURABILITY &
HIGH
AVAILABILITY
EFFICIENT
STREAMING
KV STORE OBJECT STORE EASE OF USE AT LEAST ONCE
DELIVERY
Subject-1
Subject-2
Stream
Nats-server
Streams
Streams Replication &
Placement
R1
R2
R3
NATS Cluster
- File/Memory Storage
- Configure replicas
- RAFT protocol for
consensus
- configuration for multiple
usescases
Streams Source &
Mirroring
R2 R3
R1
R1
R1
eu-west-1
eu-north-1
eu-east-1
Subject-1
Consumer
Stream
Consumer
Nats-server
Subject-1
Consumer
Stream
Consumer
VM/POD
Subject-1
Consumer
Stream
VM/POD
Subject-1
Consumer
Stream
VM/POD
- Message Replay
- Direct Get Api
- Ephemeral/Durable consumer
- File/Memory storage
- RAFT protocol for consensus
NATS Subject Mapping
- SUBJECT
PARITIONING
- CANARY
DEPLOYMENTS
- A/B TESTING - CHAOS
TESTING
- SUBJECT
MIGRATION
usecases that can be solved using
NATS
Subject
Mapping
Decentralised Auth
• Server has no idea who the users are, just what accounts exist
• Clients have a JWT with the public and private key
• Authentication requests are not vulnerable to playback attack
• Deployment can have different authorities for different parts of the system
• Chain of trust:
• Each level is authorized to do something different
• Operators – Creates accounts
• Accounts – Creates users
• Users – Creates streams/subjects, publish messages
Operator
Account
User
Account
User User User
NATS
NATS NATS
What gets stored ?
- Account & Operator JWTS
what does not get stored ?
- User JWTs
- Private Keys
Allow/deny pub
Allow deby sub
limits
Client Server
Info { nonce: …}
CONNECT {jwt: …, sig: …}
Is this sig valid ?
Is this jwt valid ?
was it signed by account I own
?
Did the operator sign the jwt ?
CONNECTING …
Decentralized Auth
Hierarchy
NATS Clustering
Unlike core NATS clustering though, each JetStream node must specify a server name and cluster name.
•# Server A - the 'seed server'
•$ nats-server -p 4222 -cluster nats://localhost:4248 --cluster_name test-cluster
•# Server B
•$ nats-server -p 5222 --cluster nats://localhost: 5248 --routes nats://localhost:4248 --cluster_name test-cluster
•# Server C
•$ nats-server -p 6222 --cluster nats://localhost:6248 --routes nats://localhost:4248 --cluster_name test-cluster
Leaf Node
Bridge 2 NATS
System
Extending a hub
(hub & spoke)
Connectivity at the
edge
NATS
Supercluster
Cluster of clusters
Use gateway connection to minimise
connectivity requirement
Planet scale
Great for data sovereignty without
restricting access for business requirements
Can make use of queue group for load
balanced response closest to user
node
C
C C
Europe
Us East Us West
node
node node node
node
node
node
node
node
NATS KV
Jetstream, the persistence layer of NATS, doesn't just allow for higher qualities
of service and features associated with 'streaming', but it also enables some
functionalities not found in messaging systems.
One such feature is the Key/Value store functionality, which allows client
applications to create 'buckets' and use them as immediately (as opposed to
eventually) consistent, persistent associative arrays.
Strength & Challenges
• Mirror stream is changing the game in messaging.
You can achieve low latency application using
memory based stream and persist its data using
mirror stream.
• Source stream can be used to aggregate data from
multiple streams, saving you the headache of
writing application to consumer from all stream
then aggregate.
• Every stream and consumer create their own
RAFT Group, which increases network
bandwidth consumption if you have many.
#we open-source
#we open-source
8
PRs
6
issues
#we open-source
Nats@Nutanix
• Multi-Tenant Nats Cluster in cloud
• 260+ R3 file streams
• 260+ R3 file durable consumers
• Implemented
• Nats Manager for cluster admin task and monitoring
• DR Service for periodic data snapshot
Nats@Nutanix
• Running on Nutanix management VM
o Integration with Nutanix process manager to run Nats container
• Running with resource constraints
o Used Nats global as well as per subject limits for resource governance
• Running on k8s cluster
o Used config maps and helm charts for easy integration
Nats@Nutanix
• New features and bugs!
o Great community support, Quick responses
• Enterprise product release management
o Upgrade at a cadence of ~6 months
References
- https://www.youtube.com/watch?v=0ZQsjVKvtTU
- https://docs.nats.io/
- https://natsbyexample.com/examples
-https://www.youtube.com/@SynadiaCommunications
https://twitter.com/nats_io
https://groups.google.com/forum/#!forum/natsio
https://slack.nats.io/
Thank You
Siddharth Jain
Senior Staff at Nutanix
Sourabh Agrawal
MTS-4 at Nutanix
linkedin.com/in/siddharth-jain-4725bb19/ linkedin.com/in/sourabhaggrawal/
slideshare.net/souravagrawal35
github.com/souravagrawal

NATS Internals, Strengths and Challenges

  • 2.
    How many ofyou have used messaging system? How many of you know about NATS ? Pulsar ? Red Panda ? Kafka ? ActiveMQ ? RabittMQ ?
  • 3.
    Siddharth Jain Senior Staffat Nutanix Sourabh Agrawal MTS-4 at Nutanix Ø Distributed System Enthusiast Ø SME For Pulsar & NATS Ø Decade of experience with apps, infra & cloud Ø Software architect with two decades of experience Ø Excited about: ü Distributed Systems ü Security ü Non-functional aspects of systems linkedin.com/in/siddharth-jain-4725bb19/ linkedin.com/in/sourabhaggrawal/ slideshare.net/souravagrawal35 https://github.com/souravagrawal
  • 5.
    What we loveabout NATS ? • Developed in GO • Configure only what you need • Cross cloud, cross geo and extended to edge • Single digit millisecond latency • Only one binary to run • Active Community on slack • Open-Sourced
  • 6.
    Why should youcare ? • CNCF Project • Over 40 client language implementations • Github: 11.2K Stars, 1.1K forks • 10+Years of consistent development
  • 7.
    What is NATS? • NATS is “Open Sourced, Apache Licensed” lightweight and high- performance messaging system designed for building distributed and scalable applications. NATS simple ecosystem is what makes it stand apart from other. It’s a client-server system with a massive performant and horizontally scalable server component. cclient client server
  • 8.
    Core NATS • NATSstarted its journey with Core NATS, where you can publish/subscribe to a subject, but the messages are “not persisted” and only active subscriber will receive the message. In case if consumer is not active it loses the message, so NATS core follows “At most once delivery”.
  • 9.
  • 10.
    Core NATS Load Distributionwith Queue Groups
  • 11.
  • 12.
  • 13.
    Streams Replication & Placement R1 R2 R3 NATSCluster - File/Memory Storage - Configure replicas - RAFT protocol for consensus - configuration for multiple usescases
  • 14.
    Streams Source & Mirroring R2R3 R1 R1 R1 eu-west-1 eu-north-1 eu-east-1
  • 15.
  • 16.
    Subject-1 Consumer Stream Consumer VM/POD Subject-1 Consumer Stream VM/POD Subject-1 Consumer Stream VM/POD - Message Replay -Direct Get Api - Ephemeral/Durable consumer - File/Memory storage - RAFT protocol for consensus
  • 17.
    NATS Subject Mapping -SUBJECT PARITIONING - CANARY DEPLOYMENTS - A/B TESTING - CHAOS TESTING - SUBJECT MIGRATION usecases that can be solved using
  • 18.
  • 19.
    Decentralised Auth • Serverhas no idea who the users are, just what accounts exist • Clients have a JWT with the public and private key • Authentication requests are not vulnerable to playback attack • Deployment can have different authorities for different parts of the system • Chain of trust: • Each level is authorized to do something different • Operators – Creates accounts • Accounts – Creates users • Users – Creates streams/subjects, publish messages
  • 20.
    Operator Account User Account User User User NATS NATSNATS What gets stored ? - Account & Operator JWTS what does not get stored ? - User JWTs - Private Keys Allow/deny pub Allow deby sub limits Client Server Info { nonce: …} CONNECT {jwt: …, sig: …} Is this sig valid ? Is this jwt valid ? was it signed by account I own ? Did the operator sign the jwt ? CONNECTING … Decentralized Auth Hierarchy
  • 21.
    NATS Clustering Unlike coreNATS clustering though, each JetStream node must specify a server name and cluster name. •# Server A - the 'seed server' •$ nats-server -p 4222 -cluster nats://localhost:4248 --cluster_name test-cluster •# Server B •$ nats-server -p 5222 --cluster nats://localhost: 5248 --routes nats://localhost:4248 --cluster_name test-cluster •# Server C •$ nats-server -p 6222 --cluster nats://localhost:6248 --routes nats://localhost:4248 --cluster_name test-cluster
  • 22.
    Leaf Node Bridge 2NATS System Extending a hub (hub & spoke) Connectivity at the edge
  • 23.
    NATS Supercluster Cluster of clusters Usegateway connection to minimise connectivity requirement Planet scale Great for data sovereignty without restricting access for business requirements Can make use of queue group for load balanced response closest to user
  • 24.
    node C C C Europe Us EastUs West node node node node node node node node node
  • 25.
    NATS KV Jetstream, thepersistence layer of NATS, doesn't just allow for higher qualities of service and features associated with 'streaming', but it also enables some functionalities not found in messaging systems. One such feature is the Key/Value store functionality, which allows client applications to create 'buckets' and use them as immediately (as opposed to eventually) consistent, persistent associative arrays.
  • 26.
    Strength & Challenges •Mirror stream is changing the game in messaging. You can achieve low latency application using memory based stream and persist its data using mirror stream. • Source stream can be used to aggregate data from multiple streams, saving you the headache of writing application to consumer from all stream then aggregate. • Every stream and consumer create their own RAFT Group, which increases network bandwidth consumption if you have many.
  • 27.
  • 28.
  • 29.
  • 30.
    Nats@Nutanix • Multi-Tenant NatsCluster in cloud • 260+ R3 file streams • 260+ R3 file durable consumers • Implemented • Nats Manager for cluster admin task and monitoring • DR Service for periodic data snapshot
  • 31.
    Nats@Nutanix • Running onNutanix management VM o Integration with Nutanix process manager to run Nats container • Running with resource constraints o Used Nats global as well as per subject limits for resource governance • Running on k8s cluster o Used config maps and helm charts for easy integration
  • 32.
    Nats@Nutanix • New featuresand bugs! o Great community support, Quick responses • Enterprise product release management o Upgrade at a cadence of ~6 months
  • 33.
    References - https://www.youtube.com/watch?v=0ZQsjVKvtTU - https://docs.nats.io/ -https://natsbyexample.com/examples -https://www.youtube.com/@SynadiaCommunications https://twitter.com/nats_io https://groups.google.com/forum/#!forum/natsio https://slack.nats.io/
  • 34.
    Thank You Siddharth Jain SeniorStaff at Nutanix Sourabh Agrawal MTS-4 at Nutanix linkedin.com/in/siddharth-jain-4725bb19/ linkedin.com/in/sourabhaggrawal/ slideshare.net/souravagrawal35 github.com/souravagrawal