Edge
Your Laravel app does not need PHP for every request
A serverless container sleeps only when nothing reaches it. What we measured, and how Brewless now publishes, redirects and searches at the edge.
In this post
A serverless container is cheap because it sleeps. Scaleway puts one to sleep after fifteen minutes without a request, and starts it again on the next one. That restart took 4.5 seconds in our test this week, for a Laravel app that answers in about a hundred milliseconds once it is awake.
So the question that decides both your bill and your slowest page is not "how fast is PHP" but "how often does a request reach PHP at all".
What decides a serverless bill?
The requests that reach your container. Every one of them starts the fifteen minutes again, so if requests arrive evenly, the share of the month the container is awake follows from that one number:
| Requests reaching the container per month | Awake |
|---|---|
| 300 | about 10% |
| 2,000 | about 50% |
| 10,000 | about 97% |
That is a model, not a measurement. Real traffic is not even, and crawlers come at night. But the shape is what we see on our own sites. A cache hit ratio of 95% sounds excellent; on a site with a million requests a month it still leaves 50,000 requests for the container, and the container never sleeps.
Pages first: what Brewless already did
Most of a public Laravel site is the same for everybody, and Brewless already let bunny.net answer those pages:
brewless/laravelgives a page without cookies and without a sessionCache-Control: public, s-maxage=…, and leaves guests without a session cookie when the page put nothing in it.- After every release, Brewless asks every page in your sitemap through the edge, so they are cached before the first visitor comes.
- With
edge.keep_pages, those pages also go into your storage zone. A small script at the edge answers from there when the cache has dropped a page, and falls back to your container when it is not there. We wrote about that in The page your CDN dropped should not wake your container. - Scanner addresses like
/wp-login.phpare refused by the edge itself.
Three things still woke the container: a page that changed between releases, a redirect table, and search.
Publishing a page without a release
Until now a page changed at the edge with a release. Publish a blog post in your CMS and it waited for the next deploy, or for the cache time to run out. Now your application says which addresses changed, after the transaction that changed them:
use Brewless\Laravel\Facades\Edge;
use Illuminate\Support\Facades\Event;
use Statamic\Events\EntrySaved;
Event::listen(EntrySaved::class, function (EntrySaved $event): void {
Edge::publish([$event->entry->url(), '/blog', '/sitemap.xml'], 'entry.saved');
});
With edge.publish: true in brewless.yml, Brewless takes the old page out of your storage zone, empties the address at the edge, asks it once more through the edge and keeps the new page. Your container was awake anyway, because someone just pressed Save. It renders the page the way it always does, with Blade or Antlers, so nothing has to be rewritten for the edge. Ten saves in a minute become one operation, and if Brewless cannot be reached, a queued retry tries again later while your site keeps serving the page it had.
A page that now answers 404 or a redirect is emptied at the edge and taken out of the zone, so you publish a deleted page's address too. A page that sets a cookie or is not public is never kept, also not through a publish.
Redirects that never reach PHP
A site that has moved keeps a table of old addresses, and every crawler that still knows them wakes your container for a 301. Brewless now keeps that table at the edge, up to 10,000 redirects, exact or as a prefix (/docs/*):
brewless.ymlrelease:
- migrate --force
- brewless:redirects --from=redirects.csv
The edge script answers the redirect before it looks for a page, also right after a release emptied the edge. Our own site coding.agency sends its 49 Route::redirect routes this way with a release command of its own; the routes stay as the fallback.
Note
A redirect that carries the visitor's query string is never kept by the edge. When the cache key leaves the query out, the next visitor would otherwise be sent on with the first one's parameters. We found that on coding.agency an hour after it went live, and fixed it the same evening.
Search without your container
A search box is answered differently for every query, so the edge cannot keep it, and every search wakes PHP. With edge.search: true the warm-up of a release makes a search index of the pages it keeps, one per domain, in your storage zone, and a published page goes into it straight away. The edge script answers /_brewless/search?q= with JSON, while the visitor types.
It searches the words of your pages: the title, the description and the main text. No facets, no spelling correction. A search that needs your database still belongs to your container.
Why your main database does not move to the edge
bunny.net also has a database, Bunny Database, which an edge script can query over HTTP. We built a small test this week, an edge script with a read-only token answering from a full-text index, and measured it from the Netherlands, 30 to 40 requests per route over a new TLS connection each time:
| Route | Median | p95 |
|---|---|---|
| Cached page from the edge | 50 ms | 61 ms |
| Edge script, no database | 55 ms | 92 ms |
| Edge script, one indexed query | 63 ms | 120 ms |
| Edge script, full-text search | 66 ms | 141 ms |
| Warm Laravel container on Scaleway | 102 ms | 113 ms |
| Cold Laravel container on Scaleway | 4,516 ms (first request) |
It is fast, and SQLite 3.45.1, foreign keys, FTS5 and transactions across several HTTP requests all worked. It is still not where your orders go:
- Preview. No general availability date and no published SLA for the database.
- No backups you can restore. No point-in-time recovery, and no import or export of a database file yet.
- Writes can be lost. bunny.net documents that a primary failover can lose up to ten seconds of confirmed writes.
- Limits. 1 GB per database during the preview.
- Every query is a round trip. From a container in Paris that is an HTTPS call per query, where PostgreSQL in the same private network is not.
So Brewless keeps your data in your own database, and puts at the edge only what can be rebuilt from it: your pages, your redirects and the search index of your pages.
When it pays, and when it does not
- A small site, up to about 100,000 requests a month: this is where the bill drops, in our cost model from roughly €60–110 to €2–16 a month at Scaleway, if every public route is answered at the edge. Leave the search box on PHP and it keeps the container awake on its own.
- A large site, millions of requests: the container is awake all day either way. The gain is that visitors get a page in 50 ms instead of 100, and a traffic spike is absorbed at the edge instead of starting more containers.
- An app most people use signed in: a dashboard or an admin panel. Edge caching changes little there. Do not expect savings.
What to do now
- Run
brewless command production "brewless:sleep". It names every page that cannot be kept at the edge, and why. - Run
brewless wakes productionto see what still reaches your container. - Turn on
edge.keep_pages, thenedge.publishand, if your site has a search box,edge.search.
Read more: Publishing to the edge · Edge cache · Brewless Edge
Frequently asked questions
Is Bunny Database a replacement for PostgreSQL in my Laravel app?
Not today. It is in public preview, keeps no backups you can restore, caps a database at 1 GB, and bunny.net documents that up to ten seconds of confirmed writes can be lost when the primary fails over. Brewless keeps your data in your own database at Scaleway and puts only your pages, redirects and a search index of your pages at the edge.
How do I publish a changed page without a deploy?
Set edge.publish to true in brewless.yml, deploy once, and call Edge::publish() from brewless/laravel with the addresses that changed, after you save. Brewless empties them at the edge, asks them again and keeps the new page in your storage zone. If Brewless cannot be reached, the queued job tries again later and your site keeps serving the page it had.
Will this make my hosting cheaper?
Only if it brings the number of requests that reach your container below a few thousand a month. Above roughly ten thousand a month, evenly spread, a container with a fifteen-minute idle timeout never sleeps, whatever your hit ratio. Large sites gain speed and resilience, not a lower Scaleway bill.
Does my visitor data leave the EU?
bunny.net is a Slovenian company, and the pull zones Brewless makes route through its European points of presence. bunny.net does not document that edge scripts run only in European points of presence, so we say a European provider with EU routing, and not that everything stays in the EU.