Slide 1

Slide 1 text

SCALE WITH NSQ a realtime distributed messaging platform @GeorgiCodes Georgi Knox - Software Engineer @ Bitly Berlin Buzzwords June 2, 2015

Slide 2

Slide 2 text

G’DAY, MY NAME IS GEORGI @GeorgiCodes

Slide 3

Slide 3 text

WHAT IS BITLY? •Popular URL shortener •analytics around how and where those links were shared •10 billion clicks per month •8000 requests per second

Slide 4

Slide 4 text

WHAT IS NSQ? • At version: 0.3.5 •Open-sourced by Bitly •written in Go •19 client libraries, 11 languages • > 3 years in production

Slide 5

Slide 5 text

GROWING PAINS •single host •synchronous writes •new feature: track metrics API metrics interweb 1 2 3

Slide 6

Slide 6 text

MESSAGING PATTERNS

Slide 7

Slide 7 text

PS Producer ConsumerA ConsumerB BROADCAST de-coupling of producers and consumers multicast: message copied and delivered to n consumers m1 m1 m2 m2

Slide 8

Slide 8 text

queue Producer ConsumerA ConsumerA m1 horizontal scalability DISTRIBUTION m2 m3

Slide 9

Slide 9 text

queue Producer ConsumerA ConsumerA fault tolerance FAILURE m2 m1 m3

Slide 10

Slide 10 text

queue Producer ConsumerA ConsumerA EVEN MORE FAILURE when all the things fail m2 m3 m1

Slide 11

Slide 11 text

NSQD

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

UNDER THE HOOD •topics and channels are independent •configurable high water mark
 (disk persistence) DiskQueue In-Memory goroutine Input Chan Output Chan

Slide 14

Slide 14 text

OUR SIMPLE EXAMPLE + NSQD •introduce nsqd •de-coupled production and consumption of data •PUB locally to nsqd via HTTP •perform work async •co-locate everything (silo) API nsqd “metrics” channel “api_event” topic metrics consumer consumer

Slide 15

Slide 15 text

SCALE HORIZONTALLY API nsqd “metrics” channel API nsqd metrics consumer consumer consumer consumer “api_event” topic “api_event” topic “metrics” channel … …

Slide 16

Slide 16 text

NSQLOOKUPD

Slide 17

Slide 17 text

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)

Slide 18

Slide 18 text

OUR SIMPLE EXAMPLE + NSQLOOKUPD •introduce nsqlookupd •discoverability •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

Slide 19

Slide 19 text

GUARANTEES •messages are delivered at least once •messages are not durable (by default) •messages received are un-ordered •consumers eventually find all topic producers

Slide 20

Slide 20 text

TOPIC & CHANNEL PAUSING “clicks” “metrics” “reporting” “achrive” paused paused F F F C
 A
 C
 H
 E DB “archive” A A A B B B C D C C D D G G G

Slide 21

Slide 21 text

NSQ ADMIN •#ephemeral channels

Slide 22

Slide 22 text

THANK-YOU!
 @GeorgiCodes big thanks to @jehiah and @imsnakes (authors of NSQ)