Entry 6 (2 to 8 Mar): Collapsing an event design down to two functions
Our first internal engineering CLI began as a TypeScript tool engineers ran on their own machines. It grew into a deployed service with a REST API, a GitHub Actions path, and a Google Chat agent that queued work through Lambda and SQS. By March it had close to ninety commands, and its rewrite spec proposed a broader platform. Async work across that platform had grown up three different ways. Chat messages went through a forwarder, a queue, and a worker. About ten event rules were hardcoded in infrastructure code, each turning an event into a command string for the worker to parse. A third pipeline handled source control webhooks on its own event bus. The three shared no code, no schemas, and no monitoring. When one scheduled command started failing, nothing alerted and nothing retried, and we found out when a human noticed stale data.
Our first answer was a configurable event subsystem. A config file would map each trigger to a target: a direct service call for predictable work, or the AI agent for anything that needed reasoning. Every invocation would report to a monitoring layer, with retries and backoff, and any failed call could escalate to the agent for investigation.
The rewrite spec replaced that design with something much smaller.

Every async event now enters through one small intake function. It validates the event against a typed schema, rejects anything it does not recognize, and turns the rest into a task message on a single queue. One worker reads the queue and handles exactly two shapes of task. A command task runs plain code, and an agent task goes to the AI. After three failed attempts a message parks in a dead-letter queue, where somebody can see it.
The split into two functions had a concrete reason. The worker image is around ten gigabytes, and its cold start is too slow to acknowledge a chat webhook inside the chat platform's timeout. A tiny intake function answers in time and leaves the heavy lifting to the queue.
The bigger gain was moving routing out of infrastructure strings and into application code. Renaming a command used to break event wiring at deploy time with no warning. Now the compiler catches it, and every mapping can be unit tested against a fixture.
The configurable version promised more, and we needed almost none of it. We needed validation, a queue, and a place for failures to land, and nothing else. A config language for triggers would have been one more thing to maintain, and it would have hidden the routing from the compiler.