Distributed Application Logic in Ruby with Redis - Jonathan Hyman, AppBoy

50 views

Published on

Appboy is an intelligent CRM for mobile-first marketers used by leading apps such as SoundCloud, Etsy, Domino’s Pizza, iHeartRadio, and more. We collect over 85 billion
data points per month from our customers’ end users and send over two billion messages to those users each month. At our scale, parallelization is a must, but distributed logic requires synchronization. We use Redis for synchronization. In this talk, I’ll go over a few use cases that we use at Appboy, such as rate limiting, and will include a deep-dive on our Redis-backed Ruby semaphore code.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
50
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Distributed Application Logic in Ruby with Redis - Jonathan Hyman, AppBoy

  1. 1. DISTRIBUTED APPLICATION LOGIC IN RUBY WITH REDIS JON HYMAN, CO-FOUNDER & CIO, APPBOY REDISCONF, 05/10/2016 - @JON_HYMAN - @APPBOY
  2. 2. S T R I C T LY C O N F I D E N T I A L / 3TV INTELLIGENT CRM FOR OUR MOBILE-CENTRIC WORLD WEARABLES PUSH NOTIFICATIONS IN-APP/ BROWSER MESSAGES FACEBOOK MOBILE/DESKTOP WEB NEWS FEED CARDS TV EMAILS
  3. 3. S T R I C T LY C O N F I D E N T I A L / 4 WE EMPOWER BRANDS TO BUILD
 LONG-TERM RELATIONSHIPS
 WITH THEIR CUSTOMERS
  4. 4. 5 We collect over 100 billion data points each month from our customers
  5. 5. 6 At this scale, parallelization is a must
  6. 6. 7 Need to be able to manage program flow
  7. 7. 8 Today’s talk is about controlling concurrency
  8. 8. RATE LIMITING API REQUESTS RATE LIMITING SEND SPEED Q&A Agenda RATE LIMITING SEND VOLUME CONTROLLING ACCESS TO SHARED RESOURCES
  9. 9. 10 Synchronization requires shared state
  10. 10. 11 We use Redis for synchronization
  11. 11. 12 In-memory database that is super fast Redis is an open source (BSD licensed), in-memory data structure store, used as database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs and geospatial indexes with radius queries. Redis has built-in replication, Lua scripting, LRU eviction, transactions and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.
  12. 12. API Requests
  13. 13. RATE LIMITING API REQUESTS Prevent customers from using more than their fair share of API calls
  14. 14. RATE LIMITING API REQUESTS At the start of each request, increment a counter for that time period DEMO
  15. 15. Send Volume
  16. 16. RATE LIMITING SEND VOLUME • Appboy customers send messages to their end users • We offer features to limit how many messages are sent • Evaluating target users and sending messages is entirely distributed • Need to control the number of messages sent at send time across many servers
  17. 17. RATE LIMITING SEND VOLUME Keep a counter of how many messages have already been sent DEMO
  18. 18. Send Speed
  19. 19. RATE LIMITING SEND SPEED Push messages • Massive push campaigns greatly increase concurrent app opens • Sometimes our customers’ infrastructure can’t handle those app opens • Our users want to cap our rate of delivery to avoid an outage
  20. 20. RATE LIMITING SEND SPEED Email messages • Email volume is a factor into spam calculations (“warm-up”) • Sending slower can prevent blocks and deferrals
  21. 21. RATE LIMITING SEND SPEED Message sending asks to send at their scheduled time, and delay as necessary
  22. 22. RATE LIMITING SEND SPEED Message sending asks to send at their scheduled time, and delay as necessary DEMO
  23. 23. Shared Resources
  24. 24. CONTROLLING SHARED RESOURCES • Increased concurrency can easily lead to overwhelming servers (especially databases) • Appboy allows customers to export raw event stream data via API that directly queries our data warehouse • Goal is to ensure that only a few queries can be running at any given time
  25. 25. CONTROLLING SHARED RESOURCES • Semaphores are the right data type for this • Conceptually, semaphores are just counters that can increment and decrement • Blocking and signaling are important concepts in semaphores
  26. 26. CONTROLLING SHARED RESOURCES • Semaphore will be implemented as a Redis list • One list element per resource • To grab resource, atomically pop an element off the list (or block) • To release a resource, atomically add the element back to the list • Handle stale locks
  27. 27. CONTROLLING SHARED RESOURCES DEMO
  28. 28. CONTROLLING SHARED RESOURCES • Can also use locks to throttle frequency of an event • We use this to flush data periodically to a database
  29. 29. CONTROLLING SHARED RESOURCES DEMO
  30. 30. Q&A JON HYMAN, CO-FOUNDER & CIO, APPBOY REDISCONF, 05/10/2016 - @JON_HYMAN - @APPBOY Code available at https://github.com/jonhyman/redisconf-concurrency-2016

×