Their shop costs โน0 a month. A finished feature stays off to keep it that way.
Snackly sells dry fruits, nuts and seeds. Their storefront and the admin panel behind it run on Cloudflare, take real payments, and cost them nothing per month to operate.
Not "nearly nothing" - the invoice does not exist. That was the constraint, not the achievement. A small Indian retailer will absorb a one-off build cost and will not absorb a recurring one, and a hosting bill is the thing that quietly kills a small store's website about a year in: the card expires, nobody notices, and the site is gone.
So the brief was to build a real shop - catalogue, cart, checkout, inventory, orders, coupons, content - inside allowances that never generate a charge.
Cloudflare's free tiers make that possible for a specific and slightly unusual reason. They fail closed. Exceed the Workers request limit and further operations return an error. Exceed D1's daily row reads and queries are blocked. Exceed the image transformation allowance and you get a 9422 back, and Cloudflare's own documentation says plainly that "you will not be charged for exceeding the limits in the Free plan."
None of these degrade into a bill. That is the whole reason this is safe to hand a client. The failure mode is downtime, not debt - and downtime is a problem you can be called about, while a surprise โน4,000 charge on somebody's personal card is a problem you find out about when the relationship ends.
The most useful thing in the repository is not the architecture. It is a feature that is built, tested, deployed and deliberately switched off, because turning it on would have started a bill in the client's name against a sentence we had already written down.
TL;DR
Static asset requests are free and unlimited, and that single line is the architecture. The storefront is a Next.js static export served by Workers Static Assets, so a customer browsing forty pages never reaches our code. Only /api/* runs the Worker, which is what keeps the whole store inside 100,000 requests a day.
Three separate pieces of code exist in their current shape because of a metered limit. Image widths are clamped to three buckets because Next's default eight would burn the transformation budget; the admin dashboard reads a nightly aggregate because summing the orders table live is the one query capable of exhausting 5 million daily row reads by itself; the catalogue runs three flat queries instead of one JOIN because D1 is metered in rows read, and a JOIN reads far more rows for the same answer.
The order-alert emails are finished and switched off. Cloudflare Email Sending requires the Workers Paid plan. The scope document told the client twice that their monthly platform cost is zero. We had misread the pricing page and said otherwise, in writing, twice - so the binding ships commented out with the reason attached rather than quietly contradicting the promise.
The free tier is metered per account, so the store had to be built in the client's account, not ours. Two clients in one account share one allowance, and a busy Diwali on one store throttles the other. It also turns handover into a role grant rather than a migration.
The admin has no login form - no password table, no session store, no reset email. Cloudflare Access gates it at the edge and the Worker re-verifies the signed assertion, because anyone who learns the origin URL can call it directly.
Image transformations took the homepage from 3,746 KB to 233 KB on a phone, and the store is using 60 of its 5,000 monthly transformations.
The free tier is a shape, not a discount
Building for a free tier is not the same as building cheaply. Every limit is a different kind of limit, and the ones that bite are rarely the ones you plan around.
- Service: What it does here
- Free allowance Workers Static Assets: every storefront page, script and stylesheet - free and unlimited
- Workers: the API and the admin logic - 100,000 requests/day, 10 ms CPU each
- D1: products, orders, customers, content - 5 M rows read/day ยท 100 k written/day ยท 5 GB
- R2: product photography - 10 GB ยท 1 M Class A ยท 10 M Class B ยท zero egress
- Image Transformations: resizing and format negotiation - 5,000 unique transformations/month
- Access: the admin login - 50 users
- Cron Triggers: nightly aggregates and backup - 5 per account
Read that as a shape and two things stand out immediately. The first is that the tightest limit is not requests or storage. It is 5,000 image transformations a month, and it is tight in a way that is easy to miss because the number sounds generous.
The second is a trap. KV allows 1,000 writes a day. That is small enough that carts, sessions or view counters in KV would work perfectly in development and fail on a moderately busy Saturday. This build uses no KV at all.
Neither of those is a performance consideration. They are both arithmetic, done before the code was written, and both changed what got built.
One line decides the architecture
Requests to static assets are free and unlimited. They do not draw down the 100,000, and they never execute your Worker. Everything else follows from that.
The storefront is a Next.js static export - plain HTML in a directory - served by Cloudflare's Asset Worker. run_worker_first in the config lists exactly /api/*, so a customer loading the homepage, browsing four categories and reading three policy pages costs zero requests against the daily cap. Only adding to a cart, placing an order or an admin action reaches the Worker at all, where a small Hono app does the routing.
Diagram: Almost every architectural decision below is an attempt to keep work above that line rather than below it. The free tier did not reward a clever design; it rewarded moving code out of the metered path. See it in the original post.
Server rendering was rejected on numbers rather than taste. The free plan gives 10 ms of CPU per invocation, and server-side rendering typically lands somewhere between 10 and 20 ms - straddling the limit rather than clearing it. The Worker size cap is 3 MiB compressed on free against 10 MiB on paid, which a Next.js SSR bundle is not comfortably inside either. Both constraints point the same way.
The cost of that choice is real and worth stating: a static page is built at deploy time and the catalogue changes whenever the client edits it. The build resolves this by fetching live values - price, stock, offers - client-side at render, so a static page is never a stale page. It does not resolve it completely, and ยง8 is what that costs.
Three places the free tier changed the code
This is the part that generalises. Each of these is ordinary code that would look different on a paid plan.
Image widths are a billing control. Next's responsive images request roughly eight widths per image by default. Cloudflare bills a transformation per unique combination of source image and settings, so at 300 catalogue images that is 2,400 unique transformations for one format, and a second format doubles it. Against a 5,000 monthly allowance, that is one busy month from costing money.
So the loader clamps every request to exactly three buckets - 400, 800 and 1200 - and uses format=auto, which serves AVIF or WebP by content negotiation and counts as one transformation rather than one per format. The comment at the top of the file is the whole point:
/**
* So widths are clamped to exactly three buckets. 300 images x 3 widths = 900
* unique transformations, permanently inside the free tier, and each bucket is
* reused across every product rather than being generated per layout.
*
* `format=auto` serves AVIF/WebP by content negotiation and counts as one
* transformation, not one per format.
*
* Changing ALLOWED_WIDTHS is a billing decision, not a styling one.
*/
Diagram: Nothing here is an optimisation. The clamped version renders identically; it just declines to generate variants nobody asked for. Framework defaults assume storage and compute are cheap, which on a metered allowance is exactly the assumption that costs money. See it in the original post.
The dashboard reads yesterday's arithmetic. An admin dashboard that sums the whole orders table on every page load is, in the file's own words, "the one query in this build capable of burning the free tier's 5 million daily row reads by itself" - because it grows with the shop and gets slower and more expensive precisely as the business succeeds. A nightly cron rebuilds a trailing 45-day window into a daily_sales table, and only today is computed live, because today changes while you are watching it.
The catalogue runs three flat queries, not one JOIN. This is the least obvious of the three. A single JOIN across products, variants and images returns a row per combination and then has to be de-duplicated in code. It is one round trip and it feels tidier. But D1 is metered in rows read, and that JOIN reads far more rows to produce the same answer. Three flat queries assembled in JavaScript read fewer.
The same file caps its page size - "an unbounded limit is a free-tier row-read leak" - because an endpoint that accepts ?limit=100000 is a way for anyone to spend the day's allowance in an afternoon.
Two smaller ones follow the same logic. Uploads are taken as the raw request body rather than as multipart form data, because parsing multipart means scanning the whole payload for boundary markers and the CPU budget is 10 ms; taking the bytes directly makes an upload almost pure I/O. And there is no PDF library for invoices, because the browser already has a renderer that produces a better file than anything worth shipping into a 10 ms budget.
The account has to be the client's
Cloudflare's free tier is metered per account. That one fact decides where the store lives. If Snackly's shop ran inside our Cloudflare account, their traffic would draw down an allowance shared with every other client in it. Two stores in one account share 100,000 requests a day, 5 GB of D1 and 10 GB of R2 - so a busy Diwali on one throttles the other, and a genuinely good month for one client puts us onto a paid plan on behalf of somebody else's business.
This is not hypothetical tidiness. When the deployment was being prepared, the account it would otherwise have deployed into was found to already hold another client's resources. The target account was checked before anything was created: no zones, no D1, nothing belonging to anyone else.
The second reason is better. A store built in the client's own account makes handover a role grant rather than a migration. There is no exporting a database, no re-pointing DNS, no window where the shop is in two places. If the relationship ends, they change one permission and everything keeps running - which is the difference between a deliverable and a dependency.
The feature that is finished and switched off
The store emails its owner when an order comes in, and sends a low-stock digest overnight. Both are built. Both are tested. Both were deployed. Neither is on.
The sequence is worth walking through, because it is three separate discoveries and only the last one is a decision.
First, the binding deployed and a real order proved the design. A live test order came back:
outcome=ok https://snacklyfoods.in/api/checkout [error] ['team email failed', 'could not find account config of sending domain'] outcome=ok
The order was written and returned an order number to the customer while the email was failing. That is the guarantee the whole notification path is built around - it runs in waitUntil and swallows every error, because an email must never cost a sale - and here it is demonstrated in production rather than asserted in a unit test.
Second, the obvious fix would have taken down the client's business email. Onboarding a domain for Cloudflare Email Sending writes MX records for bounce routing, plus SPF, DKIM and DMARC. snacklyfoods.in is not a spare domain: its MX points at Google Workspace, it already carries an SPF include and a DMARC policy, and the address the alerts go to is a live mailbox on it. A domain may carry only one SPF record - a second is a permanent error, and every message the business sends would start failing authentication. The instruction written down an hour earlier was one command away from breaking a client's mail.
Third, and this is the one that matters: it was never free. Cloudflare Email Sending requires the Workers Paid plan. The line on the pricing page about sends to verified destinations being free describes what happens once you are already paying; it is not a route onto the plan. From the commit:
The pricing page's line about sends to verified destinations being free and outside the quota describes what happens once you are already paying; it is not a way onto the plan. I had read it as one and said so twice.
That turns a technical step into a commercial one. The scope document tells the client, in writing, twice, that their monthly platform cost is zero. Switching this on starts a bill in their name against that sentence - about โน450 a month, for a feature nobody had agreed to buy.
So it is off. Not half-built, not forgotten: the binding is commented out in the config with the reason attached, sendTeamEmail returns "unbound", the nightly digest logs its count instead of sending, and no order is ever delayed or failed by an email that cannot send. The client-facing document that previously said "Included" against those emails now says they are built, deployed and not switched on, and explains why.
The alternative was available and slightly humiliating: leave it on, let it fail silently, and let the promise stand on a technicality. What made that unattractive is that it would have worked. Nobody would have noticed for months.
The admin has no login form
There is no password table in this build. No sessions table, no password reset email, no rate limiter on a login endpoint, no bcrypt. Those are all things that can be got wrong, and the way to get them right was to not have them.
Cloudflare Access sits in front of /admin and /api/admin, with a policy naming individual email
Comments
No comments yet. Start the discussion.