---
title: "Cancellable events are not events."
date: 2026-10-31
description: "What events actually solve, and why cancellable events bring back the coupling events were meant to remove. They are votes, not events."
url: https://hamza-cskn.com/blog/cancellable-events-are-not-events
---

# Cancellable events are not events.

This is not AI content. So there is no gaslighting here.

> *I’m sorry that I long ago coined the term “objects” for this topic because it gets many people to focus on the lesser idea. The big idea is “messaging”*\
> ***— Alan Kay (who coined the term ‘OOP’), in a [email](http://c2.com/cgi/wiki?AlanKayOnMessaging).***

Events are quite important concept that unlocks loosely coupled software architectures. They have proven themselves in countless production systems, and there’s a lot to learn from **why** they work well.

Best way to understand something is understanding problem behind them. Before go for ‘cancellable events’, we first need to look at what events solve.

## What events solves?

I worked very hard and finally split the problems that events solve into 2 pure element.

### Epistemic Dependency Problem

Imagine you’re writing a function. Your function have to do some operations. Also you know a few exist functions. Each of these functions do one part of the operations you need therefore your function must call these functions. Everything looks simple.

```js
function placeOrder(order) {
  saveOrder(order);
  sendConfirmationEmail(order);
  reserveInventory(order);
  trackAnalytics(order);
}
```

During writing your function you were know what operations your function would need. It is the crucial part. Maybe tomorrow you’ll want to send SMS. It is enough to add one line and call another function.

However, what happen if you are not the author of the code? Maybe you added it as dependency. Editing your dependency is not sustainable.

You want to add new line there but you can’t. Root cause of that problem is that the author cannot know what operations you’ll need.

![A two-by-two grid: you know what to do but not when; your dependency knows when to do it but not what](https://hamza-cskn.com/_astro/when-vs-what.Uoi9zG8T.png)

Your dependency knows **when**. You know **what**. This is the classic case for inversion of control, or as it’s often called, the Hollywood Principle: “Don’t call us, we’ll call you.”

If author want to allow external operations they must manage ‘functions’ as objects. So author can handle these ‘operations’ while being agnostic of their details. Once that harness complete, you can provide your functions as objects to there and they can call your functions.

Usually we use a system that takes events and runs functions they want. We call these mechanism ‘Event Bus’ .

```js
function placeOrder(order) {
  saveOrder(order);
  sendConfirmationEmail(order);
  reserveInventory(order);
  trackAnalytics(order);
  events.emit("orderPlaced", order);
}


// your codebase
events.on("orderPlaced", sendSms);
```

### Temporal Dependency Problem

Imagine you wrote 2 function. Ones input is others output. Such as:

```js
while (true) {
  consume(produce());
}
```

The two functions take turns. The consumer waits for the producer, which is fine. But the producer also waits for the consumer, and that’s the problem.

```js
queue = []

//worker1
while (true) {
  queue.put(produce());
}

//worker2
while (true) {
  consume(queue.get());
}
```

With that, we’ve fixed the problem. The producer puts its result into a queue without waiting for the consumer. (Technically, it still waits for the queue, but a push is fast enough to ignore.) Events make this possible. A producer that announces what happened needs no answer, so its events can be queued.

Now, imagine you have too many object to produce and consume. However your producer (or consumer) is too slow while other one is too fast. Let’s say the every producer produces every *p* seconds and every consumer consumes every *c* seconds. So you thought you can reduce consumer count to save your resources (maybe for more producers). The best idea is using a single common queue, *p* amount of producer and *c* amount of consumer.

![p producers push items into one shared queue, and c consumers take items from it; each producer makes one item every p seconds, each consumer handles one every c seconds](https://hamza-cskn.com/_astro/shared-queue.BhoQUBD4.png)

Congratulations. Now you’ve a system that abstracts producers and consumers via queue. Eugster et al. reached the same three in [*The Many Faces of Publish/Subscribe*](https://dl.acm.org/doi/10.1145/857076.857078), a well-regarded 2003 survey in ACM Computing Surveys.

1. **Space decoupling:** Your producer counts and consumer counts are does not matter.
2. **Time decoupling:** Consumers can be interrupted without missing anything produced in the meantime. (persistence)
3. **Synchronization decoupling:** Your producers do not wait for the consumers.

![Three diagrams of a publisher, an event service and subscribers: space decoupling (one publish notifies many subscribers), time decoupling (publisher and subscriber need not be up at the same time) and synchronization decoupling (neither side blocks the other)](https://hamza-cskn.com/_astro/pubsub-decoupling.DQwCxqVH.png)
*The Many Faces of Publish/Subscribe, ACM Computing Surveys, Vol. 35, No2, June 2003.*

## What is cancellable events?

Imagine you have a function that you know when to run and how to do. Looks like you do not need an event mechanism but you want to allow other dependencies, aborting your function before do its job.

```js
function placeOrder(order) {
  const event = { order, cancelled: false };
  events.emit("beforeOrderPlaced", event);

  if (event.cancelled) return;

  saveOrder(order);
}
```

I won’t lie. It’s attractive. Countless codebases use it and they’re happy with their life. The DOM lets you cancel default behaviors, like following a link or submitting a form. Game modding APIs like Spigot let you cancel in-game actions, which is exactly what makes mods possible. Today I won’t say you the idea behind ‘cancellable events’ is bad.

## Why cancellable events are not events?

In event streaming, events are information flowing from producers to consumers. In programming, they’re signals to run some functions. Both borrow the word from its everyday meaning: something that happens. Once it has happened, it can’t be changed.

An event cannot be cancelled due to its nature. You can only create another event that says it’s cancelled. You may create an Outlook Calendar event then cancel it. But it is two distinct event. Create and cancel events.

## Problems with cancellable events

Imagine you are developer of a plugin. There are many event listener(consumer) in your plugin and the platform author may add more plugins like yours.

1. You may want to cancel an event, but you need to ensure other consumers can’t uncancel it. This can be solved by disallowing uncancelling by design, if you’re okay with losing that ability.
2. You may want to do an operation if the event is not cancelled. Some systems partially solve this issue by adding a monitor level priority that disallows cancelling events and guarantees these consumers are last. So, you know the state you see is final. However if you want to also cancel the event (it is required than probably you think), you cannot.

In case of you are just an author of single consumer, it makes impossible to guarantee knowing what priority should your consumer introduce.

In case of you are author of event bus, it requires being aware what consumer touches what state. So, you can configure priority of your consumers. This is a good case. You have to be careful when updating behavior of the consumers and you have to sacrifice multi-threading, lockless design. In theory, you can. In practice, if you are a system admin you probably does not want to inspect all listeners of all plugins you’ve loaded.

> ***The problem with ‘cancellable events’ is they contradicts with event definition and recreates problems that typical events solve. The problem is not idea behind cancellable events.***

1. Producer must be synchronized with consumers. **It recreates the temporal coupling issue.**
2. Consumers always share a mutable state: is the event cancelled? flag. It inherently makes order of consumption matters. **It recreates the epistemic coupling.** In events, if your consumers does not share a mutable state, order of consumption is not important. However in cancellable events that situation is guaranteed. So you have to prioritize your consumers.

The idea behind cancellable events is a simple voting mechanism. You choose how votes are resolved: the last vote wins, the majority wins, the highest priority wins, or everyone has to agree (like [**two-phase commit**](https://en.wikipedia.org/wiki/Two-phase_commit_protocol)). Call it a vote, and it no longer breaks any promise an event makes.

Voting is a good concept that solves important problems. But they aren’t the problems events solve. An event answers “what happened?” A vote answers “should it happen?”. Intentionally when you see name of ‘event’, probably you won’t think about priorities, majority, consensus etc.
