Zookeeper big sonata

Anh Le
Anh LeData Scientist at Viettel Cyber Space Center
Introduction to Zookeeper
Anh Le
@BigSonata
What is a Distributed System?
A distributed system consists of multiple
computers that communicate through a
computer network and interact with each
other to achieve a common goal.
-Wikipedia
Coordination in a Distributed System?
Coordination: An act that multiple nodes must perform together.
Examples:
Leader Election
Managing group membership
Managing metadata
Synchronization (Semaphore, Mutex...)
Coordination in a Distributed System?
To coordinate, processes can
Exchange messages through network
Read/Write using shared storage
Use distributed locks
Problems for exchanging messages
Message delays
Processor speed
Clock drift
Use case for Master-Work Applications
Problems
Master crashes
Worker crashes
Communication failures
Use case for Master-Work Applications
Problems for Master Crashes
Use a backup master
Recover the latest state ?
Backup master may suspect the primary master has crashed ?
!> Split Brain scenario
Use case for Master-Work Applications
Problems for Worker Crashes
Master must detect worker crashes
Recover assigned tasks
Problems for Communication Failures
Execute a same task only once
Introduction to ZooKeeper
An open source, performant coordination
service for distributed applications
Was a sub project of Hadoop but is now a
Apache top-level project
Exposes common services in simple interface
Leader Election
Naming
Configuration management
Locks & Synchronization
Group Service
→ Don't have to write them from scratch
ZooKeeper Use cases
Distributed Cluster Management
Node join/leave
Node statuses in real time
Distributed synchronization
Locks
Barriers
Queues
ZooKeeper Use cases
Apache Hbase use ZooKeeper to
Elect a cluster master
Keep track of available servers
Keep cluster metadata
Apache Kafka use Zookeeper to
Detect crashes
Implement topic discovery
Maintain state for topics
ZooKeeper Guarantees
Sequential Consistency: Updates are applied in order
Atomicity: Updates either succeed or fail
Single System Image: A client sees the same view of the service
regardless of the ZK server it connects to.
Reliability: Updates persists once applied, till overwritten by some
clients.
Timeliness: The clients’ view of the system is guaranteed to be up-
to-date within a certain time bound. (Eventual Consistency)
ZooKeeper Services
All machines store a copy of the data (in memory)
A leader is elected on service startup
Clients only connect to a single server & maintains a TCP
connection.
Client can read from any server, writes go through the leader &
needs majority consensus.
ZooKeeper Data Model
ZooKeeper has a hierarchal name space.
Each node is called as a ZNode.
Every ZNode has data (given as byte[])
ZNode paths:
canonical, absolute, slash-separated
no relative references.
names can have Unicode characters
ZNode
Maintain a stat structure with version
numbers for data changes, ACL changes
and timestamps.
Version numbers increases with
changes
Data is read and written in its entirety
ZNode types
Persistent Nodes
exists till explicitly deleted
Ephemeral Nodes
exists as long as the session is active
can’t have children
Sequence Nodes (Unique Naming)
append a monotonically increasing counter to the end of path
applies to both persistent & ephemeral nodes
ZNode watches
Clients can set watches on znodes:
NodeChildrenChanged
NodeCreated
NodeDataChanged
NodeDeleted
Changes to a znode trigger the watch and ZooKeeper sends
the client a notification.
Watches are one time triggers.
Watches are always ordered.
Client sees watched event before new ZNode data.
ZNode APIs
String create(path, data, acl, flags)
void delete(path, expectedVersion)
Stat setData(path, data, expectedVersion)
(data, Stat) getData(path, watch)
Stat exists(path, watch)
String[] getChildren(path, watch)
→ Each API has its own asynchronous version also
ZooKeeper Recipes
Recipe: Leader Election
/master
Recipe: Leader Election
Continuous watching on znodes requires reset of watches
after every events / triggers
Too many watches on a single znode creates the “herd
effect” - causing bursts of traffic and limiting scalability
Recipe: Leader Election (Improved)
1.All participants create an ephemeral-sequential
node on the same election path.
2.The node with the smallest sequence number is
the leader.
3.Each “follower” node listens to the node with the
next lower seq. number
4.Upon leader removal go to
election-path and find a new leader,
or become the leader if it has the lowest sequence
number.
1.Upon session expiration check the election state
and go to election if needed
Zookeeper Programming
https://github.com/anhldbk/Zookeeper-
Demo
Zookeeper Programming
Zookeeper Programming
Zookeeper Programming
Difficult to use Zookeeper APIs
Connection Issues:
Initial connection: Requires a handshake before executing any
operations (create(), delete()...)
Session expiration: Clients are expected to watch for this state
and close and re-create the ZooKeeper instance.
Zookeeper Programming
Difficult to use Zookeeper APIs
Recoverable Errors:
When creating a sequential ZNode on the server, there is the
possibility that the server will successfully create the ZNode but
crash prior to returning the node name to the client.
There are several recoverable exceptions thrown by the
ZooKeeper client. Users are expected to catch these exceptions
and retry the operation.
Zookeeper Programming
Difficult to use Zookeeper APIs
Recipes:
The standard ZooKeeper "recipes" (locks, leaders, etc.) are only
minimally described and subtly difficult to write correctly..
Zookeeper Programming with Curator
lCurator- The Netflix Zookeeper library
Zookeeper Programming with Curator
Zookeeper Programming with Curator
Zookeeper for Our Systems
Zookeeper  big sonata
1 of 32

Recommended

Distributed system coordination by zookeeper and introduction to kazoo python... by
Distributed system coordination by zookeeper and introduction to kazoo python...Distributed system coordination by zookeeper and introduction to kazoo python...
Distributed system coordination by zookeeper and introduction to kazoo python...Jimmy Lai
6.2K views35 slides
Apache Zookeeper by
Apache ZookeeperApache Zookeeper
Apache ZookeeperNguyen Quang
2K views26 slides
Apache zookeeper 101 by
Apache zookeeper 101Apache zookeeper 101
Apache zookeeper 101Quach Tung
231 views16 slides
Apache Zookeeper Explained: Tutorial, Use Cases and Zookeeper Java API Examples by
Apache Zookeeper Explained: Tutorial, Use Cases and Zookeeper Java API ExamplesApache Zookeeper Explained: Tutorial, Use Cases and Zookeeper Java API Examples
Apache Zookeeper Explained: Tutorial, Use Cases and Zookeeper Java API ExamplesBinu George
4.2K views11 slides
Apache PIG by
Apache PIGApache PIG
Apache PIGAnuja Gunale
204 views48 slides
BigData_TP2: Design Patterns dans Hadoop by
BigData_TP2: Design Patterns dans HadoopBigData_TP2: Design Patterns dans Hadoop
BigData_TP2: Design Patterns dans HadoopLilia Sfaxi
29.7K views6 slides

More Related Content

What's hot

Systèmes multi agents concepts et mise en oeuvre avec le middleware jade by
Systèmes multi agents concepts et mise en oeuvre avec le middleware jadeSystèmes multi agents concepts et mise en oeuvre avec le middleware jade
Systèmes multi agents concepts et mise en oeuvre avec le middleware jadeENSET, Université Hassan II Casablanca
32.8K views112 slides
Chapitre 5 classes abstraites et interfaces by
Chapitre 5  classes abstraites et interfacesChapitre 5  classes abstraites et interfaces
Chapitre 5 classes abstraites et interfacesAmir Souissi
2K views9 slides
Zookeeper Introduce by
Zookeeper IntroduceZookeeper Introduce
Zookeeper Introducejhao niu
1.2K views42 slides
Traitement distribue en BIg Data - KAFKA Broker and Kafka Streams by
Traitement distribue en BIg Data - KAFKA Broker and Kafka StreamsTraitement distribue en BIg Data - KAFKA Broker and Kafka Streams
Traitement distribue en BIg Data - KAFKA Broker and Kafka StreamsENSET, Université Hassan II Casablanca
38K views129 slides
Modern Algorithms and Data Structures - 1. Bloom Filters, Merkle Trees by
Modern Algorithms and Data Structures - 1. Bloom Filters, Merkle TreesModern Algorithms and Data Structures - 1. Bloom Filters, Merkle Trees
Modern Algorithms and Data Structures - 1. Bloom Filters, Merkle TreesLorenzo Alberton
30K views49 slides
Avro introduction by
Avro introductionAvro introduction
Avro introductionNanda8904648951
3.1K views22 slides

What's hot(20)

Chapitre 5 classes abstraites et interfaces by Amir Souissi
Chapitre 5  classes abstraites et interfacesChapitre 5  classes abstraites et interfaces
Chapitre 5 classes abstraites et interfaces
Amir Souissi2K views
Zookeeper Introduce by jhao niu
Zookeeper IntroduceZookeeper Introduce
Zookeeper Introduce
jhao niu1.2K views
Modern Algorithms and Data Structures - 1. Bloom Filters, Merkle Trees by Lorenzo Alberton
Modern Algorithms and Data Structures - 1. Bloom Filters, Merkle TreesModern Algorithms and Data Structures - 1. Bloom Filters, Merkle Trees
Modern Algorithms and Data Structures - 1. Bloom Filters, Merkle Trees
Lorenzo Alberton30K views
Trusts You Might Have Missed by Will Schroeder
Trusts You Might Have MissedTrusts You Might Have Missed
Trusts You Might Have Missed
Will Schroeder4.6K views
UML Part 3- diagramme de séquences mansouri by Mansouri Khalifa
UML Part 3- diagramme de séquences mansouriUML Part 3- diagramme de séquences mansouri
UML Part 3- diagramme de séquences mansouri
Mansouri Khalifa6.7K views
BigData_TP1: Initiation à Hadoop et Map-Reduce by Lilia Sfaxi
BigData_TP1: Initiation à Hadoop et Map-ReduceBigData_TP1: Initiation à Hadoop et Map-Reduce
BigData_TP1: Initiation à Hadoop et Map-Reduce
Lilia Sfaxi45K views
Pig Latin, Data Model with Load and Store Functions by Rupak Roy
Pig Latin, Data Model with Load and Store FunctionsPig Latin, Data Model with Load and Store Functions
Pig Latin, Data Model with Load and Store Functions
Rupak Roy143 views
Introduction to Storm by Chandler Huang
Introduction to Storm Introduction to Storm
Introduction to Storm
Chandler Huang20.1K views
diagramme de séquence UML by Amir Souissi
diagramme de séquence UMLdiagramme de séquence UML
diagramme de séquence UML
Amir Souissi21.4K views
BigData_TP3 : Spark by Lilia Sfaxi
BigData_TP3 : SparkBigData_TP3 : Spark
BigData_TP3 : Spark
Lilia Sfaxi31.3K views
Système de détection d'intrusion (Intrusion Detection System) by YousraChahinez
Système de détection d'intrusion (Intrusion Detection System)Système de détection d'intrusion (Intrusion Detection System)
Système de détection d'intrusion (Intrusion Detection System)
YousraChahinez197 views
Cassandra nice use cases and worst anti patterns by Duyhai Doan
Cassandra nice use cases and worst anti patternsCassandra nice use cases and worst anti patterns
Cassandra nice use cases and worst anti patterns
Duyhai Doan6.1K views
Apache Kafka 0.8 basic training - Verisign by Michael Noll
Apache Kafka 0.8 basic training - VerisignApache Kafka 0.8 basic training - Verisign
Apache Kafka 0.8 basic training - Verisign
Michael Noll178K views

Similar to Zookeeper big sonata

CrawlerLD - Distributed crawler for linked data by
CrawlerLD - Distributed crawler for linked dataCrawlerLD - Distributed crawler for linked data
CrawlerLD - Distributed crawler for linked dataRaphael do Vale
641 views26 slides
Software architecture for data applications by
Software architecture for data applicationsSoftware architecture for data applications
Software architecture for data applicationsDing Li
192 views30 slides
Zookeeper Tutorial for beginners by
Zookeeper Tutorial for beginnersZookeeper Tutorial for beginners
Zookeeper Tutorial for beginnersjeetendra mandal
142 views13 slides
Networking threads by
Networking threadsNetworking threads
Networking threadsNilesh Pawar
8.7K views35 slides
Leo's Notes about Apache Kafka by
Leo's Notes about Apache KafkaLeo's Notes about Apache Kafka
Leo's Notes about Apache KafkaLéopold Gault
38 views20 slides
Multi threaded programming by
Multi threaded programmingMulti threaded programming
Multi threaded programmingAnyapuPranav
111 views18 slides

Similar to Zookeeper big sonata(20)

CrawlerLD - Distributed crawler for linked data by Raphael do Vale
CrawlerLD - Distributed crawler for linked dataCrawlerLD - Distributed crawler for linked data
CrawlerLD - Distributed crawler for linked data
Raphael do Vale641 views
Software architecture for data applications by Ding Li
Software architecture for data applicationsSoftware architecture for data applications
Software architecture for data applications
Ding Li192 views
Networking threads by Nilesh Pawar
Networking threadsNetworking threads
Networking threads
Nilesh Pawar8.7K views
Multi threaded programming by AnyapuPranav
Multi threaded programmingMulti threaded programming
Multi threaded programming
AnyapuPranav111 views
Shopzilla On Concurrency by Will Gage
Shopzilla On ConcurrencyShopzilla On Concurrency
Shopzilla On Concurrency
Will Gage657 views
Parallel Processing (Part 2) by Ajeng Savitri
Parallel Processing (Part 2)Parallel Processing (Part 2)
Parallel Processing (Part 2)
Ajeng Savitri1.3K views
Winter is coming? Not if ZooKeeper is there! by Joydeep Banik Roy
Winter is coming? Not if ZooKeeper is there!Winter is coming? Not if ZooKeeper is there!
Winter is coming? Not if ZooKeeper is there!
Joydeep Banik Roy412 views
NodeJS guide for beginners by Enoch Joshua
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginners
Enoch Joshua1.1K views
Talon systems - Distributed multi master replication strategy by Saptarshi Chatterjee
Talon systems - Distributed multi master replication strategyTalon systems - Distributed multi master replication strategy
Talon systems - Distributed multi master replication strategy
OS Module-2.pptx by bleh23
OS Module-2.pptxOS Module-2.pptx
OS Module-2.pptx
bleh2326 views
Developing Actors in Azure with .net by Marco Parenzan
Developing Actors in Azure with .netDeveloping Actors in Azure with .net
Developing Actors in Azure with .net
Marco Parenzan80 views
Asynchronous Python with Twisted by Adam Englander
Asynchronous Python with TwistedAsynchronous Python with Twisted
Asynchronous Python with Twisted
Adam Englander1.8K views

Zookeeper big sonata

  • 2. What is a Distributed System? A distributed system consists of multiple computers that communicate through a computer network and interact with each other to achieve a common goal. -Wikipedia
  • 3. Coordination in a Distributed System? Coordination: An act that multiple nodes must perform together. Examples: Leader Election Managing group membership Managing metadata Synchronization (Semaphore, Mutex...)
  • 4. Coordination in a Distributed System? To coordinate, processes can Exchange messages through network Read/Write using shared storage Use distributed locks Problems for exchanging messages Message delays Processor speed Clock drift
  • 5. Use case for Master-Work Applications Problems Master crashes Worker crashes Communication failures
  • 6. Use case for Master-Work Applications Problems for Master Crashes Use a backup master Recover the latest state ? Backup master may suspect the primary master has crashed ? !> Split Brain scenario
  • 7. Use case for Master-Work Applications Problems for Worker Crashes Master must detect worker crashes Recover assigned tasks Problems for Communication Failures Execute a same task only once
  • 8. Introduction to ZooKeeper An open source, performant coordination service for distributed applications Was a sub project of Hadoop but is now a Apache top-level project Exposes common services in simple interface Leader Election Naming Configuration management Locks & Synchronization Group Service → Don't have to write them from scratch
  • 9. ZooKeeper Use cases Distributed Cluster Management Node join/leave Node statuses in real time Distributed synchronization Locks Barriers Queues
  • 10. ZooKeeper Use cases Apache Hbase use ZooKeeper to Elect a cluster master Keep track of available servers Keep cluster metadata Apache Kafka use Zookeeper to Detect crashes Implement topic discovery Maintain state for topics
  • 11. ZooKeeper Guarantees Sequential Consistency: Updates are applied in order Atomicity: Updates either succeed or fail Single System Image: A client sees the same view of the service regardless of the ZK server it connects to. Reliability: Updates persists once applied, till overwritten by some clients. Timeliness: The clients’ view of the system is guaranteed to be up- to-date within a certain time bound. (Eventual Consistency)
  • 12. ZooKeeper Services All machines store a copy of the data (in memory) A leader is elected on service startup Clients only connect to a single server & maintains a TCP connection. Client can read from any server, writes go through the leader & needs majority consensus.
  • 13. ZooKeeper Data Model ZooKeeper has a hierarchal name space. Each node is called as a ZNode. Every ZNode has data (given as byte[]) ZNode paths: canonical, absolute, slash-separated no relative references. names can have Unicode characters
  • 14. ZNode Maintain a stat structure with version numbers for data changes, ACL changes and timestamps. Version numbers increases with changes Data is read and written in its entirety
  • 15. ZNode types Persistent Nodes exists till explicitly deleted Ephemeral Nodes exists as long as the session is active can’t have children Sequence Nodes (Unique Naming) append a monotonically increasing counter to the end of path applies to both persistent & ephemeral nodes
  • 16. ZNode watches Clients can set watches on znodes: NodeChildrenChanged NodeCreated NodeDataChanged NodeDeleted Changes to a znode trigger the watch and ZooKeeper sends the client a notification. Watches are one time triggers. Watches are always ordered. Client sees watched event before new ZNode data.
  • 17. ZNode APIs String create(path, data, acl, flags) void delete(path, expectedVersion) Stat setData(path, data, expectedVersion) (data, Stat) getData(path, watch) Stat exists(path, watch) String[] getChildren(path, watch) → Each API has its own asynchronous version also
  • 20. Recipe: Leader Election Continuous watching on znodes requires reset of watches after every events / triggers Too many watches on a single znode creates the “herd effect” - causing bursts of traffic and limiting scalability
  • 21. Recipe: Leader Election (Improved) 1.All participants create an ephemeral-sequential node on the same election path. 2.The node with the smallest sequence number is the leader. 3.Each “follower” node listens to the node with the next lower seq. number 4.Upon leader removal go to election-path and find a new leader, or become the leader if it has the lowest sequence number. 1.Upon session expiration check the election state and go to election if needed
  • 25. Zookeeper Programming Difficult to use Zookeeper APIs Connection Issues: Initial connection: Requires a handshake before executing any operations (create(), delete()...) Session expiration: Clients are expected to watch for this state and close and re-create the ZooKeeper instance.
  • 26. Zookeeper Programming Difficult to use Zookeeper APIs Recoverable Errors: When creating a sequential ZNode on the server, there is the possibility that the server will successfully create the ZNode but crash prior to returning the node name to the client. There are several recoverable exceptions thrown by the ZooKeeper client. Users are expected to catch these exceptions and retry the operation.
  • 27. Zookeeper Programming Difficult to use Zookeeper APIs Recipes: The standard ZooKeeper "recipes" (locks, leaders, etc.) are only minimally described and subtly difficult to write correctly..
  • 28. Zookeeper Programming with Curator lCurator- The Netflix Zookeeper library
  • 31. Zookeeper for Our Systems