Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Flash Sale Engineering

Flash Sale Engineering

From stores with ads in the Super Bowl to selling Kanye’s latest album, Shopify has built a name for itself handling some of the world’s largest flash sales. These high profile events generate write-heavy traffic that can be four times our platform’s baseline throughput and don’t lend themselves to off-the-shelf solutions.

This talk is the story of how we engineered our platform to survive large bursts of traffic. Since it’s not financially sound for Shopify to have the required capacity always running, we built queueing and page caching layers into our Nginx load balancers with Lua. To guarantee these solutions worked, we tested them with a purpose-built load testing service.

Although flash sales are unique to commerce platforms, the lessons we learn from them are applicable to any services that experience bursts of traffic.

Online version: https://youtu.be/-I4tIudkArY

Emil Stolarsky

September 30, 2016
Tweet

More Decks by Emil Stolarsky

Other Decks in Programming

Transcript

  1. Flash Sale Engineering
    by @EmilStolarsky

    View full-size slide

  2. 2
    Who’s this ugly baby?

    View full-size slide

  3. 4
    Flash Sales

    View full-size slide

  4. 5
    Black Friday

    View full-size slide

  5. 9
    Super Bowl Ads

    View full-size slide

  6. 10
    #KylieLipKit

    View full-size slide

  7. 11
    tl;dr This is a big deal

    View full-size slide

  8. 12
    Write Heavy Traffic

    View full-size slide

  9. 19
    How Shopify works

    View full-size slide

  10. 20
    RESQUE WORKER
    THE INTERNET
    LB
    RAILS
    MYSQL MEMCACHED REDIS

    View full-size slide

  11. 21
    RESQUE WORKER
    THE INTERNET
    LB
    RAILS
    MYSQL MEMCACHED REDIS

    View full-size slide

  12. 22
    22
    RESQUE WORKER
    THE INTERNET
    LB
    RAILS
    MYSQL MEMCACHED REDIS

    View full-size slide

  13. 23
    23
    THE INTERNET
    LB
    RAILS
    RESQUE WORKER
    MYSQL MEMCACHED REDIS

    View full-size slide

  14. 24
    24
    RESQUE WORKER
    THE INTERNET
    LB
    RAILS
    MYSQL MEMCACHED REDIS

    View full-size slide

  15. 25
    25
    RESQUE WORKER
    THE INTERNET
    LB
    RAILS
    MYSQL MEMCACHED REDIS

    View full-size slide

  16. 26
    26
    RESQUE WORKER
    THE INTERNET
    LB
    RAILS
    MYSQL MEMCACHED REDIS

    View full-size slide

  17. 27
    27
    RESQUE WORKER
    THE INTERNET
    LB
    RAILS
    MYSQL MEMCACHED REDIS

    View full-size slide

  18. 28
    1. Right Tool
    2. Heat Shield
    3. Order out of Chaos

    View full-size slide

  19. 30
    Robust Piece of Software

    View full-size slide

  20. 32
    1. Right Tool
    2. Heat Shield
    3. Order out of Chaos

    View full-size slide

  21. 33
    Back Pressure

    View full-size slide

  22. 35
    LB RAILS
    USER
    GET /checkout

    View full-size slide

  23. 36
    LB RAILS
    USER
    GET /checkout GET /throttle_page

    View full-size slide

  24. 37
    LB RAILS
    USER
    GET /checkout GET /throttle_page
    200: (cached by LB)
    200: throttle page

    View full-size slide

  25. 38
    LB RAILS
    USER
    GET /checkout GET /throttle_page
    200: (cached by LB)
    200: throttle page
    GET /checkout?poll=1
    200: throttle page

    View full-size slide

  26. 39
    LB RAILS
    USER
    GET /checkout GET /throttle_page
    200: (cached by LB)
    200: throttle page
    GET /checkout?poll=1
    200: throttle page
    GET /checkout?poll=1
    GET /checkout?poll=1

    View full-size slide

  27. 40
    LB RAILS
    USER
    GET /checkout GET /throttle_page
    200: (cached by LB)
    200: throttle page
    GET /checkout?poll=1
    200: throttle page
    302: set checkout pass
    GET /checkout?poll=1
    GET /checkout?poll=1
    302: /checkout

    View full-size slide

  28. 41
    1. Right Tool
    2. Heat Shield
    3. Order out of Chaos

    View full-size slide

  29. 43
    Picture of shop queue

    View full-size slide

  30. 44
    Stateless* fair queueing

    View full-size slide

  31. 45
    * - Almost Stateless

    View full-size slide

  32. 46
    PROCESS
    PID CONTROLLER
    SENSOR
    Controller Output
    Setpoint Process Variable
    Measured Process
    Variable
    Disturbances
    Feedback System

    View full-size slide

  33. 47
    Stateless fair queueing
    t
    Timeline of timestamp in cookie

    View full-size slide

  34. 48
    Stateless fair queueing
    t
    Lag delimiter

    View full-size slide

  35. 49
    Stateless fair queueing
    t
    low priority
    high priority

    View full-size slide

  36. 50
    Stateless fair queueing 1
    Bucket of high priority requests (max 16)

    View full-size slide

  37. 51
    Stateless fair queueing
    t
    1
    high priority

    View full-size slide

  38. high priority
    52
    Stateless Fair queueing
    low priority
    16
    t

    View full-size slide

  39. low priority
    53
    Stateless Fair queueing
    t
    8
    high priority

    View full-size slide

  40. 54
    Stateless Fair queueing
    t
    12
    low priority
    high priority

    View full-size slide

  41. 55
    Stateless Fair queueing
    t
    10
    low priority
    high priority

    View full-size slide

  42. 56
    Stateless fair queueing
    t
    1
    high priority

    View full-size slide

  43. 57
    But… Why?

    View full-size slide

  44. 59
    Reputation

    View full-size slide

  45. 60
    Flash Sales Payments

    View full-size slide

  46. 61
    Payments Gaming

    View full-size slide

  47. 62
    Gaming Tweets

    View full-size slide

  48. 64
    Throttling Queueing

    View full-size slide

  49. 65
    Blank Slide
    We’re hiring!

    View full-size slide

  50. 66
    Blank Slide
    Thanks!
    Fo llow m e o n Tw it te r @Em ilSt ol arsky

    View full-size slide