Share
Embed
Transcript
115 slides
-
! NSQ a realtime distributed messaging platform https://github.com/bitly/nsq @imsnakes April
24th 2014 - GopherCon Matt Reiferson - CTO at Torando Labs -
BIG THINGS HAVE SMALL BEGINNINGS •boss says: “I want metrics!”
•single host •synchronous writes API interweb 1 2 -
BIG THINGS HAVE SMALL BEGINNINGS •boss says: “I want metrics!”
•single host •synchronous writes API metrics interweb 1 2 3 -
Distributed Message Bus THE GOAL provide a unifying distributed system
to receive and disseminate event data -
TOPICS AND CHANNELS •a topic is a distinct stream of
messages •a topic has one or more channels •topics and channels are created at runtime •messages are pushed to consumers combine pubsub, distribution, and queueing nsqd “clicks” Topics -
TOPICS AND CHANNELS •a topic is a distinct stream of
messages •a topic has one or more channels •topics and channels are created at runtime •messages are pushed to consumers combine pubsub, distribution, and queueing nsqd “metrics” Channels “clicks” Topics -
TOPICS AND CHANNELS •a topic is a distinct stream of
messages •a topic has one or more channels •topics and channels are created at runtime •messages are pushed to consumers combine pubsub, distribution, and queueing nsqd “metrics” Channels “clicks” Topics “spam_analysis” -
TOPICS AND CHANNELS •a topic is a distinct stream of
messages •a topic has one or more channels •topics and channels are created at runtime •messages are pushed to consumers combine pubsub, distribution, and queueing nsqd “metrics” Channels “clicks” Topics “spam_analysis” “archive” -
TOPICS AND CHANNELS •a topic is a distinct stream of
messages •a topic has one or more channels •topics and channels are created at runtime •messages are pushed to consumers combine pubsub, distribution, and queueing nsqd “metrics” Channels “clicks” Topics “spam_analysis” “archive” Consumers -
TOPICS AND CHANNELS •a topic is a distinct stream of
messages •a topic has one or more channels •topics and channels are created at runtime •messages are pushed to consumers combine pubsub, distribution, and queueing nsqd “metrics” Channels “clicks” Topics “spam_analysis” “archive” Consumers -
TOPICS AND CHANNELS •a topic is a distinct stream of
messages •a topic has one or more channels •topics and channels are created at runtime •messages are pushed to consumers combine pubsub, distribution, and queueing nsqd “metrics” Channels “clicks” Topics “spam_analysis” “archive” Consumers -
TOPICS AND CHANNELS •a topic is a distinct stream of
messages •a topic has one or more channels •topics and channels are created at runtime •messages are pushed to consumers combine pubsub, distribution, and queueing nsqd “metrics” Channels “clicks” Topics “spam_analysis” “archive” Consumers A A A -
TOPICS AND CHANNELS •a topic is a distinct stream of
messages •a topic has one or more channels •topics and channels are created at runtime •messages are pushed to consumers combine pubsub, distribution, and queueing nsqd “metrics” Channels “clicks” Topics “spam_analysis” “archive” Consumers A A A -
TOPICS AND CHANNELS •a topic is a distinct stream of
messages •a topic has one or more channels •topics and channels are created at runtime •messages are pushed to consumers combine pubsub, distribution, and queueing nsqd “metrics” Channels “clicks” Topics “spam_analysis” “archive” Consumers A A A -
TOPICS AND CHANNELS •a topic is a distinct stream of
messages •a topic has one or more channels •topics and channels are created at runtime •messages are pushed to consumers combine pubsub, distribution, and queueing nsqd “metrics” Channels “clicks” Topics “spam_analysis” “archive” Consumers A A A -
TOPICS AND CHANNELS •a topic is a distinct stream of
messages •a topic has one or more channels •topics and channels are created at runtime •messages are pushed to consumers combine pubsub, distribution, and queueing nsqd “metrics” Channels “clicks” Topics “spam_analysis” “archive” Consumers A A A B B B -
TOPICS AND CHANNELS •a topic is a distinct stream of
messages •a topic has one or more channels •topics and channels are created at runtime •messages are pushed to consumers combine pubsub, distribution, and queueing nsqd “metrics” Channels “clicks” Topics “spam_analysis” “archive” Consumers A A A B B B -
TOPICS AND CHANNELS •a topic is a distinct stream of
messages •a topic has one or more channels •topics and channels are created at runtime •messages are pushed to consumers combine pubsub, distribution, and queueing nsqd “metrics” Channels “clicks” Topics “spam_analysis” “archive” Consumers A A A B B B -
TOPICS AND CHANNELS •a topic is a distinct stream of
messages •a topic has one or more channels •topics and channels are created at runtime •messages are pushed to consumers combine pubsub, distribution, and queueing nsqd “metrics” Channels “clicks” Topics “spam_analysis” “archive” Consumers A A A B B B -
UNDER THE HOOD •topics and channels are independent •configurable high
water mark (disk persistence) •“bounded” memory footprint DiskQueue In-Memory goroutine Input Chan Output Chan -
DE-COUPLE •PUB locally to nsqd via HTTP •perform work async
•co-locate everything (silo) API nsqd “metrics” channel “api_event” topic metrics consumer consumer -
SCALE HORIZONTALLY API nsqd “metrics” channel API nsqd metrics consumer
consumer consumer consumer “api_event” topic “api_event” topic “metrics” channel … … -
NSQ NSQD API consumer NSQ NSQD API NSQ NSQD API
consumer nsqlookupd nsqlookupd TYPICAL NSQ CLUSTER •enable distributed and decentralized topologies •no centralized broker •nsqlookupd instances are independent (no coordinatation) -
NSQ NSQD API consumer NSQ NSQD API NSQ NSQD API
consumer nsqlookupd nsqlookupd PUBLISH TYPICAL NSQ CLUSTER •enable distributed and decentralized topologies •no centralized broker •nsqlookupd instances are independent (no coordinatation) -
NSQ NSQD API consumer NSQ NSQD API NSQ NSQD API
consumer nsqlookupd nsqlookupd PUBLISH REGISTER TYPICAL NSQ CLUSTER •enable distributed and decentralized topologies •no centralized broker •nsqlookupd instances are independent (no coordinatation) -
NSQ NSQD API consumer NSQ NSQD API NSQ NSQD API
consumer nsqlookupd nsqlookupd PUBLISH REGISTER DISCOVER TYPICAL NSQ CLUSTER •enable distributed and decentralized topologies •no centralized broker •nsqlookupd instances are independent (no coordinatation) -
NSQ NSQD API consumer NSQ NSQD API NSQ NSQD API
consumer nsqlookupd nsqlookupd PUBLISH REGISTER DISCOVER SUBSCRIBE TYPICAL NSQ CLUSTER •enable distributed and decentralized topologies •no centralized broker •nsqlookupd instances are independent (no coordinatation) -
DISCOVERABILITY •introduce nsqlookupd •producers and consumers come and go •other
services can discover and subscribe to this topic API nsqd “metrics” channel “api_event” topic API nsqd “metrics” channel “api_event” topic -
DISCOVERABILITY •introduce nsqlookupd •producers and consumers come and go •other
services can discover and subscribe to this topic API nsqd “metrics” channel “api_event” topic API nsqd “metrics” channel “api_event” topic nsqlookupd TCP nsqlookupd TCP -
DISCOVERABILITY •introduce nsqlookupd •producers and consumers come and go •other
services can discover and subscribe to this topic API nsqd “metrics” channel “api_event” topic API nsqd “metrics” channel “api_event” topic nsq_to_file nsq_to_file nsqlookupd TCP nsqlookupd TCP “archive” channel -
DISCOVERABILITY •introduce nsqlookupd •producers and consumers come and go •other
services can discover and subscribe to this topic API nsqd “metrics” channel “api_event” topic API nsqd “metrics” channel “api_event” topic nsq_to_file nsq_to_file nsqlookupd TCP nsqlookupd TCP “archive” channel 1 - query nsqlookupd! for topic “api_event” HTTP -
DISCOVERABILITY •introduce nsqlookupd •producers and consumers come and go •other
services can discover and subscribe to this topic API nsqd “metrics” channel “api_event” topic API nsqd “metrics” channel “api_event” topic 2 - connect to all discovered producers nsq_to_file nsq_to_file nsqlookupd TCP nsqlookupd TCP “archive” channel 1 - query nsqlookupd! for topic “api_event” HTTP -
TO INFINITY AND BEYOND nsqlookupd nsqlookupd nsqd nsqd Datacenter A
Datacenter B nsq_to_nsq -
TO INFINITY AND BEYOND nsqlookupd nsqlookupd nsqd nsqd Datacenter A
Datacenter B nsq_to_nsq -
TO INFINITY AND BEYOND nsqlookupd nsqlookupd nsqd nsqd Datacenter A
Datacenter B nsq_to_nsq -
GUARANTEES •messages are delivered at least once •messages are not
durable (by default) •messages received are un-ordered •consumers eventually find all topic producers -
BACK PRESSSSSSSSSSSSURE •clients control flow - RDY state •concurrency knob
•processing fails? •slow down rate •bad message? •limit attempts •delay re-processing Incoming Msgs Msg Handler Timeout - - Check Timeout Full Throttle success Timeout == 0 RDY N -
BACK PRESSSSSSSSSSSSURE •clients control flow - RDY state •concurrency knob
•processing fails? •slow down rate •bad message? •limit attempts •delay re-processing Incoming Msgs Msg Handler Timeout ++ Timeout - - Check Timeout Full Throttle success fail Timeout == 0 RDY N -
BACK PRESSSSSSSSSSSSURE •clients control flow - RDY state •concurrency knob
•processing fails? •slow down rate •bad message? •limit attempts •delay re-processing Incoming Msgs Msg Handler Pause Timeout ++ Timeout - - Check Timeout Full Throttle success fail Timeout == 0 RDY N RDY 0 -
BACK PRESSSSSSSSSSSSURE •clients control flow - RDY state •concurrency knob
•processing fails? •slow down rate •bad message? •limit attempts •delay re-processing Incoming Msgs Msg Handler Backoff Expired Pause Timeout ++ Timeout - - Check Timeout Full Throttle success fail Timeout == 0 RDY N RDY 0 -
BACK PRESSSSSSSSSSSSURE •clients control flow - RDY state •concurrency knob
•processing fails? •slow down rate •bad message? •limit attempts •delay re-processing Incoming Msgs Msg Handler Test Water Backoff Expired Pause Timeout ++ Timeout - - Check Timeout Full Throttle success fail Timeout == 0 RDY N RDY 0 RDY 1 -
BACK PRESSSSSSSSSSSSURE •clients control flow - RDY state •concurrency knob
•processing fails? •slow down rate •bad message? •limit attempts •delay re-processing Incoming Msgs Msg Handler Test Water Backoff Expired Pause Timeout ++ Timeout - - Check Timeout Full Throttle success fail Timeout > 0 Timeout == 0 RDY N RDY 0 RDY 1 -
TOPIC & CHANNEL PAUSING “clicks” “metrics” “reporting” “achrive” C A
C H E DB A A A B B B -
TOPIC & CHANNEL PAUSING “clicks” “metrics” “reporting” “achrive” C A
C H E DB A A A B B B -
TOPIC & CHANNEL PAUSING “clicks” “metrics” “reporting” “achrive” paused C
A C H E DB C D C C D D -
TOPIC & CHANNEL PAUSING “clicks” “metrics” “reporting” paused C A
C H E DB “archive” C D C C D D -
TOPIC & CHANNEL PAUSING “clicks” “metrics” “reporting” C A C
H E DB “archive” C D C C D D -
TOPIC & CHANNEL PAUSING “clicks” “metrics” “reporting” C A C
H E DB “archive” C D C C D D -
TOPIC & CHANNEL PAUSING “clicks” “metrics” “reporting” C A C
H E DB “archive” C D C C D D -
TOPIC & CHANNEL PAUSING “clicks” “metrics” “reporting” C A C
H E DB “archive” D D D -
TOPIC & CHANNEL PAUSING “clicks” “metrics” “reporting” C A C
H E DB “archive” -
TOPIC & CHANNEL PAUSING “clicks” “metrics” “reporting” paused F F
F C A C H E DB “archive” -
TOPIC & CHANNEL PAUSING “clicks” “metrics” “reporting” paused F F
F C A C H E DB “archive” G G G -
TOPIC & CHANNEL PAUSING “clicks” “metrics” “reporting” paused F F
F C A C H E DB “archive” G G G -
TOPIC & CHANNEL PAUSING “clicks” “metrics” “reporting” paused F C
A C H E DB “archive” G G G -
TOPIC & CHANNEL PAUSING “clicks” “metrics” “reporting” paused F C
A C H E DB “archive” G -
TOPIC & CHANNEL PAUSING “clicks” “metrics” “reporting” C A C
H E DB “archive” -
ONE MORE THING •#ephemeral channels •channel sampling •TLS / Snappy
•telemetry over statsd / HTTP -
SUMMARY •github.com/bitly/nsq •10,300 lines of Go •19 client libraries, 11
languages •over 2 years in production -
SUMMARY •github.com/bitly/nsq •10,300 lines of Go •19 client libraries, 11
languages •over 2 years in production