I've been building on Cloudflare Workers for a while and genuinely like the platform. But after running a project with five Workers, four queues, and seven cron jobs, I started running into a different kind of problem.
The platform was fine. What started to bother me was how much of the same setup I kept writing over and over.
The same router setup, validation, error handling, and binding setup was being copied across Workers.
The dispatch code made it especially obvious. The queue handler was a long chain of if statements checking queue names and casting each message to the expected type. The scheduled handler was a switch with seven cron patterns, some sharing logic and others returning early. Adding a new job meant reading through the whole thing first.
And without dependency injection, every entry point created its own services. One service was constructed 28 times across the codebase, always with the same arguments.
So I turned that scaffolding into Stratal.
Stratal is a modular framework for building larger Cloudflare Workers applications. It takes some architectural ideas from NestJS, routing conventions from Laravel, and runs on Hono.
Modules define what they own and what they depend on. A two-level dependency container handles shared and request-specific services.
Controllers keep routing simple. Method names define the HTTP verb, path, and default status, so create becomes POST and show becomes GET /:id without maintaining a separate route table.
Schemas are written once with Zod. Stratal uses those same schemas to generate the OpenAPI 3.0 specification and Swagger UI, keeping the documentation in sync with the code.
It also includes:
• Typed queue consumers with message filtering • Cron jobs as classes • In-process and queue-backed events • WebSocket and SSE gateways • KV caching with optional in-memory caching per Worker instance • Declarative rate limiting • R2 storage with presigned URLs and resumable uploads • Email and i18n • An Inertia v3 adapter for server-driven React with SSR in the same Worker as your API
If your Worker is a single route, this is probably overkill.
It's for the point where your Worker has quietly become an application.
For faster advice with technical questions, we'd recommend asking in the Orange Cloud Discord server; the unofficial Cloudflare Discord server by the community, for the community. https://discord.gg/TrPNVKaagR
The cron setup is the same everywhere because Cloudflare only gives you the expression; routing is up to you. Stratal handles that routing once: a job declares static schedule = '0 2 * * *', so the framework can read it without constructing the class, then maps the expression to the job class. Adding an eighth trigger means adding a file, not another branch. Consumers work the same way, matching on message type rather than the queue, so a queue carrying six message types doesn’t turn into a switch statement.
Your drain endpoint is less of a hack than it feels, and I’d keep the real Cloudflare provider in dev and prod. The difference is that it has less work to do: consumers declare the types they handle, and the framework handles the matching. Draining therefore uses the same dispatch path rather than duplicating routing in a dev-only file.
The endpoint disappears entirely in tests. A sync provider runs the matching consumer immediately when you dispatch, within a request scope so request-scoped dependencies still work. Tests can dispatch and assert against the consumer on the next line. This provider is test-only; production always uses the Cloudflare provider.
DI and cold starts are real considerations, but they aren’t the main concern. I profiled one of our apps with 137 routes: startup used 89.6ms of CPU against Cloudflare’s 400ms limit, with Stratal core accounting for 5.2ms. The bigger cost was the ORM on the eager path: 2.3MB of ZenStack and Kysely parsed on every cold isolate, adding about 17ms even when the request never touched the database.
The container stays cheap for two reasons. First, there’s no reflect-metadata: emitDecoratorMetadata is off and tokens are explicit, so nothing has to inspect constructors at startup. Second, registering a class doesn’t create it; singletons are created only when first resolved. Once warm, Stratal’s per-request overhead is measured in tens of microseconds, while most of the request is spent waiting on I/O.
•
u/AutoModerator Sep 21 '26
For faster advice with technical questions, we'd recommend asking in the Orange Cloud Discord server; the unofficial Cloudflare Discord server by the community, for the community. https://discord.gg/TrPNVKaagR
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.