All Articles

Underflow

Some of us grew up with the rumour that a good way to meet an eligible partner was to go to the supermarket on a Friday night and see who had bananas in their shopping trolley. Right now, it seems like the best advertisement of social value is a pack of toilet paper in the trolley. It’s been funny and sometimes tragic to see the toilet paper flying off shelves recently.

But is all as it seems?

Is there really a nationwide shortage, or are our eyes playing tricks on us? Is this instead a strange quirk in a system that’s more sensitive to subtle changes than we might expect?

(I remain skeptical about the banana story, incidentally.)

Maybe we’re gawking at a relatively harmless buffer underflow. Now you may ask: buffer underflow? huh?

Buffers

Pretty much all of life is about stuff flowing around. Stuff gets produced, and consumed. Factories produce toilet paper, we consume it. Trees produce oxygen, we breath it. Friends send us messages, we read them.

But good luck finding any situation where production and consumption are always exactly matched.

So we introduce the idea of a buffer. In computer science, there are a few ways that things can be stored, in order to connect producers and consumers that work at different speeds or different times. In a buffer, the order that things arrive and leave has to stay the same: no queue jumpers! A cache is similar in some ways, but the order doesn’t matter: items enter and leave by name. It’s a bit more like post office boxes - you can look into a box with a specific name, and grab something if it’s there. A pool, on the other hand, is just a collection of similar items.

The supermarket shelves containing toilet paper: a collection of indistinguishable items. But I’m going to call them a buffer, because I want to talk about “buffer underrun”.

These kind of buffers are everywhere. A brewery produces beer faster than you can drink it, so it gets stored in kegs at the pub. You don’t earn money at exactly the same speed as you spend it, so it gets stored in your bank account. Your emails get stored in your email account until you’re ready to read them and delete them. Your dirty clothes get buffered in your laundry basket until…

Buffers can overflow, though. If you wear clothes faster than you wash them, your laundry basket will fill up and your clothes will start landing on the floor. Even if you’re diligent, your clothes basket could start overflowing if you have a rainy week and can’t do the washing.

They can underflow too. If you spend money faster than you earn it for too long, you might one day find that your bank account is empty, and you can’t pay for things anymore. That’s a buffer underflow.

Balance

In the real world, if things aren’t in balance, they get out of control. If you have more toilet paper delivered to your supermarket than you’re selling, the whole place is going to fill up. Conversely, it’s possible to run out if you sell more than you have delivered.

How sensitive is this balance?

Some things are very stable. You can push them as hard as you like, and they won’t budge. Some things are unstable. Bump them slightly and they’ll fall over.

What about balance where there’s supply and demand with a buffer in between? The system falls over when there’s an overflow or underflow. The system is stable if we can change the input or the output a lot without overflowing or underflowing.

If the buffer is very big compared to the size of the flow, the system will be stable. As the buffer becomes small compared to the flow rate, it does less and less to stabilise the flow.

So this is what has happened with toilet paper. It’s very bulky compared to its value. A pallette full of toilet paper is worth much, much less than a pallette full of chocolate, so the supermarket is motivated to store as little as possible. They’d prefer to have space for chocolate. Or soft drinks. And that’s normally fine, because the flow is very predictable. Toilet paper doesn’t fall in and out of fashion on a daily basis. It’s pretty much always in vogue. Maybe sometimes people like a frog print, and other times seashells. And occassionally pictures of politicians.

The system is ordinarily very stable on its own, so there’s no need to stabilise it with a large buffer.

Until demand suddenly changes by a large amount. If every shopper decides to do something that’s individually sensible and buy a little bit extra, suddenly every buffer in every supermarket is empty.

Illusion

The illusion is produced because we see only the empty buffer, and we can’t see the stable flows on either side.

Contrast this with what’s happened with facemasks and handwash: in those cases, consumption has actually increased, so in these cases, any shortages may not be an illusion.

But! It’s important to acknowledge that whilst the shortage was originally an illusion, the illusion did spook people enough that behaviour has changed. The output flow from supermarket shelves right now has probably doubled or more - it’s much more than a glitch right now.

Cascading failure

There’s a secondary effect at work. Sometimes a service gets overwhelmed and breaks down. But all the people wanting service still haven’t been satisfied, so they go looking elsewhere. Soon you have unsatisfied swarms hitting any service that’s still available and overwhelming it too. That’s cascading failure.

In the case of toilet paper, it happens when the supermarket runs out, and people don’t lose interest in toilet paper. So they go looking at the local chemist. But the chemist runs out too, so the hordes go and try their luck at the local servo, or Bunnings. Or they start stealing from the local pub. Pretty soon the whole system is down. A toilet paper blackout.

Another kind of cascading failure occurs when people go and find the toilet paper shelf empty and then start looking around and cascading the failure into surrounding items: tissues and paper towels. Now we have a failure that’s rippling out of one system and into another.

Conclusion

Entertaining as it’s been, it’s clear that for some, it’s also been distressing. It’s likely this pattern will be repeated in coming weeks, and it’s probably worthwhile being able to distinguish when it’s just a quirk of the system so that we don’t grow too upset about it.

[Thank you to Sam Johnston for drawing my attention to what’s really behind the empty shelves]