In one of my stints when solving a demand <> supply mismatch problem where in we would occasionally have a lot more demand than riders to full the orders. We had a very unique problem where in the delta between demand and supply would spike massively and sharply, albeit for a few minutes but nevertheless. We used a PID controller to solve for this problem.
The Conundrum
This specific issue had to be dealt with since, our supply was limited. By not dealing with this mismatch we would give poor experience to all consumers.
More Potential Orders > Riders mean consumers will have to wait in a queue for the old orders to be full filled before the new ones can be serviced. This would increase ETA for ones lower in the queue. An alternative was using fees. To help prioritise orders for those who were willing to pay a fee to get their orders prioritised.
Fee vs No Fee
The fee vs no fee strategy to prioritise orders is a separate discussion. Fee could have potential implications especially during growth stage of an app and might affect retention numbers. So, provided it’s been decided that fees is one of the ways to go about this. This specific use case offers a potential approach of using a PID controller to adjust the fees. We propose using it as a lever to shape the demand so all set of users get a good quality of service and a consistent one.
Challenges
The challenges to solving this sharp and sudden demand <> supply mismatch is that it’s often difficult to infer reasons. At a micro store level that’s serving a few thousand customers, often these spike in orders can be driven entirely by obvious reasons such as rain. Any geographical trigger such as traffic in that specific area and any other idiosyncratic localised functions etc.
The gist being that these are often difficult to infer and predict at a such localised level. Given the scale of values, a pure predictive model will not work. Because most of the leading indicators of this stress are too varied, collect and use to estimate the demand spikes.
The Potential Approach
As we thought deeper into the problem, we realised that we might want to not necessarily have to predict this demand. But rather be able to react fast and aggressively to this demand <> supply mismatch and on a real time basis.
This need to be able to react fast and in real time to control this demand spike led us to PID controller. You want to control demand since this in specific case, the supply is difficult to adjust fast. In most cases, supply would be difficult to tweak fast. I have been a similar approach is used by AWS to built out their auto scaling system’s bid values as well.
A PID controller is a control system concept where in you use a error feedback loop to control a specific input to the system. This input is then used to bring the system’s output closer to the target or reference number. This control theory is actively used for motor control where in you want to maintain a certain speed for it. The input is the electric pulse to the motor controller.

How did it fare?
There is a bit of fine tuning needed to head the coefficients for the proportional, integral and derivative parts but overall, the system worked in a brilliant fashion. This system though was subjected to some business guardrails that were needed. This was to make sure the inputs to the system are within bounds of business constraints aka the surge fees had a clear range between which it could be moved.
We were able in real time, able to adjust the fees to shape the demand and the consumer experience was not degraded. The brilliant part about this was that the system was fairly light weight and easy to implement and integrate.
Learnings
As the world moves to the era of AI, LLMs and dynamic software systems. Sometimes, the answers are already available in the pure engineering disciplines such as Electrical and Mechanical systems. The mathematical concepts developed in these areas already deal with dynamic systems and have physical constraints in terms of heat, strength of material etc.
All dynamical systems need well designed guard rails to be able to use in production. These could be soft and hard in nature but a pivotal to be able to use systems in production.
The systems work best when the scope of solution or answers is limited, this allows the dynamic system to be stable. This concept can be understood more deeply from control theory but it’s beyond the scope of this specific blog.

Leave a Reply