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 Slide

  2. 2
    Who’s this ugly baby?

    View Slide

  3. 3

    View Slide

  4. 4
    Flash Sales

    View Slide

  5. 5
    Black Friday

    View Slide

  6. 6

    View Slide

  7. 7

    View Slide

  8. 8
    Kanye West

    View Slide

  9. 9
    Super Bowl Ads

    View Slide

  10. 10
    #KylieLipKit

    View Slide

  11. 11
    tl;dr This is a big deal

    View Slide

  12. 12
    Write Heavy Traffic

    View Slide

  13. 13

    View Slide

  14. 14

    View Slide

  15. 15

    View Slide

  16. 16

    View Slide

  17. 17

    View Slide

  18. 18

    View Slide

  19. 19
    How Shopify works

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  29. 29
    Nginx

    View Slide

  30. 30
    Robust Piece of Software

    View Slide

  31. 31
    Lua

    View Slide

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

    View Slide

  33. 33
    Back Pressure

    View Slide

  34. 34

    View Slide

  35. 35
    LB RAILS
    USER
    GET /checkout

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  39. 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 Slide

  40. 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 Slide

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

    View Slide

  42. 42

    View Slide

  43. 43
    Picture of shop queue

    View Slide

  44. 44
    Stateless* fair queueing

    View Slide

  45. 45
    * - Almost Stateless

    View Slide

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

    View Slide

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

    View Slide

  48. 48
    Stateless fair queueing
    t
    Lag delimiter

    View Slide

  49. 49
    Stateless fair queueing
    t
    low priority
    high priority

    View Slide

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

    View Slide

  51. 51
    Stateless fair queueing
    t
    1
    high priority

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  56. 56
    Stateless fair queueing
    t
    1
    high priority

    View Slide

  57. 57
    But… Why?

    View Slide

  58. 58

    View Slide

  59. 59
    Reputation

    View Slide

  60. 60
    Flash Sales Payments

    View Slide

  61. 61
    Payments Gaming

    View Slide

  62. 62
    Gaming Tweets

    View Slide

  63. 63
    Nginx

    View Slide

  64. 64
    Throttling Queueing

    View Slide

  65. 65
    Blank Slide
    We’re hiring!

    View Slide

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

    View Slide