7 minute read In the first post of this series, I outlined Shopify’s history with flash sales, our move to Nginx and Lua to help manage traffic, and the initial attempt we made to throttle traffic that didn’t account sufficiently for customer experience. We had underestimated the impact of not giving preference to customers who’d entered the queue at the beginning of the sale, and now we needed to find another way to protect the platform without ruining the customer experience.
Overview
This article discusses how Shopify improved its handling of high-write traffic during flash sales by implementing a stateless fair queueing system using scriptable load balancers. It details the transition from a database-dependent approach to a more efficient method using timestamps and PID controllers to prioritize user requests based on their entry time into the queue.
What You'll Learn
How to implement a stateless fair queueing system for handling high-write traffic
Why using PID controllers can optimize request handling in distributed systems
How to avoid single points of failure in load balancing architectures
Prerequisites & Requirements
- Understanding of load balancing and traffic management concepts
- Familiarity with PID controllers and control theory(optional)
Key Questions Answered
How does Shopify ensure fairness in user queue times during flash sales?
What role do PID controllers play in managing traffic at Shopify?
What problems arise from using a data store for managing user timestamps?
How did the implementation of the new queueing system affect customer experience?
Key Statistics & Figures
Technologies & Tools
Some links below are affiliate links. We may earn a commission if you make a purchase.
Key Actionable Insights
1Implement a timestamp-based priority system for user requests to enhance fairness during high-traffic events.This approach allows for prioritizing users who entered the queue earlier, ensuring a better customer experience during critical sales.
2Utilize PID controllers to dynamically adjust thresholds in response to real-time traffic conditions.This technique helps maintain optimal request handling without manual intervention, adapting to varying load conditions effectively.
3Avoid relying on centralized data stores for critical user data during peak traffic.Instead, consider stateless solutions that can operate independently across multiple data centers to enhance reliability and performance.