Why the Appshots server runs on Effect

Published on
Written by
Irere Emmanuel

Appshots has a small codebase and an awkward server problem. One request kicks off work that runs for minutes, calls two AI models, holds credits, and has to refund exactly the frames that did not finish if anything stops halfway. The first version was ordinary async TypeScript. The second runs on Effect. Here is why we switched, in the order the reasons showed up.

Cancellation stopped being a parameter

In the first version, stopping a generation meant passing an abort signal down through every layer that did work. Whether a failure was a timeout or a person pressing stop was a flag read off that signal. Any new layer that forgot to pass it along could keep rendering, and keep charging, after the user had cancelled.

Effect treats running work as a tree. Stop the parent and every child stops with it, cleaning up as it goes. A whole set's generation is one branch of that tree, so cancelling it is a single call, and it works the same whether the stop comes from the same process or another one. Timeouts are declared once, at the top of the work they bound, instead of being smuggled through every function in between.

Nothing has to remember to be cancellable. It just is.

Errors got names

Our functions used to return shapes like "not found" or "conflict" and let every caller sort them out with a switch. Forget a case and the request fell through to a generic 500. Somewhere along the way an error type became unknown, which is another way of saying nobody knew what could go wrong.

In Effect every failure a function can produce is part of its type, with a name. Insufficient credits, a set that does not exist, a frame that would not render. The API maps each name to a status code exactly once. Add a new failure and forget to map it, and the build fails instead of a customer.

The rule we adopted along the way: if an error channel says unknown, that is a bug, not a type.

Tests stopped lying

The old test suite replaced modules with mocks. When a query's signature changed, the mocks did not, and the suite stayed green while the code was wrong. It happened twice before we noticed the pattern.

Effect's dependency model gives every external thing a named interface that production and tests both implement. A fake database is checked against the same contract as the real one, so the change that used to slip through is now a compile error in the test file. We deleted every module mock.

What it cost

Effect has a real learning curve. Reading it is easy; knowing how to shape a program takes a couple of weeks, and the style guide that ships with the package is better than anything online. We are also on a release candidate, so we pin the version and read the installed source when a signature is in doubt.

And it must never reach the browser. The server, shared and client code live in separate folders, and checking that the runtime is absent from the client bundle is part of every build.

Would we do it again

Yes, and sooner. The tell was never the size of the codebase. It was the shape of the work: anything that outlives a request and moves money is a poor fit for promises, and we spent months building worse versions of what Effect already had. Every one of the problems above was fixed by deleting code.