Handling Redis failover
  with ZooKeeper
        Ryan LeCompte
      BaRuCo Lightning Talk
        September 2012
Me
• Rubyist at Spreecast in San Francisco
• redis_failover, method_locator,
  synchronizable
• http://github.com/ryanlecompte
• lecompte@gmail.com
• @ryanlecompte
Typical Redis Setup
Master Dies
    :-(
What happens to your data and
connected clients?

•   Resque Jobs?

•   Sidekiq Jobs?

•   Cached pages?

•   Cached stats?

•   Rubygems?
Scramble to manually
reconfigure slave as master
Update all Redis clients to
talk to the new master
Restart production services
so they can see the new config
What do we really
  want to do?
   NOTHING
Failover should be safe
    and automatic
Let’s talk about
ZooKeeper
Open source Apache
Project (originally from
        Yahoo)
Provides a set of simple
primitives to help you
     build powerful
distributed applications
Automatically handles
network partitions &
quorum management
Replicated, Highly
Available, Ordered,
Battle-proven
Used by Yahoo, Netflix,
 Rackspace, Hadoop,
     Neo4j, etc
How can I use
ZooKeeper in my
  architecture?
Distributed
     Configuration
(update thread pool sizes &
   other settings without
 requiring a server restart)
Distributed Locking
 (only one process should be
able to do something at a time)
Priority Queues
Leader Election, Group
 Membership & more
Practical application:
Using ZooKeeper to
  build automatic
  failover for Redis
redis_failover
http://github.com/ryanlecompte/redis_failover
Provides a smart “failover-
aware” client that wraps
existing Ruby client for
Redis
Clients automatically
connect to ZooKeeper
and register for watch
notifications
Node Managers monitor
Redis servers for availability
and automatically inform
clients of failover via
ZooKeeper
Architecture
RedisFailover::Client
                Example
# create new client with list of ZooKeeper servers
client = RedisFailover::Client.new(:zkservers => 'localhost:2181,localhost:
2182,localhost:2183')

# write operations automatically routed to master
client.set(‘foo’, ‘bar’)

# read operations automatically routed to a slave
client.smembers(‘data’)
Companies using
     redis_failover
• Papertrail
• Backupify
• MediaPiston
• IDT Corporation
• others
Consider incorporating
ZooKeeper into your overall
architecture.
Utilize the primitives it gives you for
solving your next distributed
programming challenge.
Don’t let your Redis servers
go unmanaged in production.
Consider using
redis_failover to sleep
better at night.
Thanks for listening!
       http://github.com/ryanlecompte/redis_failover

              Questions? Ask me at the beach!

Handling Redis failover with ZooKeeper