What my clinical-trials site really costs on Azure: the bill, the 3.5 GB search VM, and the AI spend I forgot to measure
I build hipa.ai alone. It's a clinical-trials search site: 608,221 trial records in Elasticsearch, about 93K URLs in the sitemap, and, at its peak, about 190 LLM-written news articles a week on top. It started on March 1
I build hipa.ai alone. It's a clinical-trials search site: 608,221 trial records in Elasticsearch, about 93K URLs in the sitemap, and, at its peak, about 190 LLM-written news articles a week on top. It started on March 19, 2026. As of this week the repo has a bit over 1,100 commits.
People keep asking me what something like this costs to run. I didn't actually know, so I pulled the numbers from Azure Cost Management instead of guessing. Some of them surprised me.
The stack (until two weeks ago)
- Next.js 16, standalone build, on Azure App Service (Windows), with a staging slot for swap deploys
- MongoDB for content, leads and state
- A self-hosted Elasticsearch VM for trials, facilities and companies
- Azure Blob Storage for infographics and sitemaps
- Cloudflare Free in front of everything
- OpenAI, Gemini and Claude for article generation
One thing you need to know first: hipa.ai never had an App Service plan of its own. It shared a Premium v3 P1 Windows plan with another of my sites. Shared plans make cost splits ugly, so I'll show both the parts that belong only to hipa.ai and the shared parts.
The Azure bill, line by line
Everything below is amortized cost from the Cost Management query API, so reserved-instance purchases are spread across the months they cover.
| Item | Sep 2026 | Oct 2026 | Notes |
|---|---|---|---|
| Shared P1v3 Windows plan (reserved) | $84.78 | $154.60 | Shared with another site |
| Elasticsearch VM compute (reserved, 1 vCPU / 3.5 GB) | $15.09 | $17.50 | Also shared |
| Elasticsearch VM disks (128 GB premium + 64 GB + OS) | $22.56 | $21.03 | |
| Web app egress bandwidth | $12.10 | $13.22 | hipa.ai only |
| Public blob storage (images, sitemaps) | $1.82 | $1.96 | hipa.ai only |
| Key Vault + Log Analytics | $0.03 | $0.04 | Basically free |
Put together, the hipa.ai-only lines come to about $15 a month. The shared compute it was sitting on came to $120–195 a month. I haven't looked into why the plan line nearly doubled from September to October, so I'm not going to make up a reason.
Here's what surprised me: bandwidth cost more than storage, Key Vault and logging put together, and most of that bandwidth was bots. That's the next post.
The 3.5 GB Elasticsearch box that kept dying
I put Elasticsearch on the smallest VM I could reserve: 1 vCPU, 3.5 GB RAM, no swap. The Java process settles at about 2.6 GB RSS. That leaves roughly 900 MB for the OS, Kibana and anything else.
The kernel OOM killer took out the java process on April 2, April 14, April 15 (during an import test), June 12 and July 19. The July one wasn't even caused by my code. Ubuntu's check-new-release ran, memory spiked, and Elasticsearch was the biggest process on the box.
The part that hurt: the systemd unit didn't restart it. It sat in failed (Result: signal) until I logged in by hand. Getting back to yellow (285 shards, single node) took about 6 minutes. The site mostly kept serving during the outage, because Cloudflare and Next's ISR cache covered the cached pages. Any cache-miss render that needed Elasticsearch failed.
The fix I should have made on day one costs two lines:
# /etc/systemd/system/elasticsearch.service.d/override.conf
[Service]
Restart=on-failure
RestartSec=20s
The real lesson: a 3.5 GB node is fine for serving a 600K-document index. It is not fine for serving plus bulk imports plus Kibana plus apt. So I moved the importer off the box, and later moved Elasticsearch itself.
Moving search off Azure, and the bandwidth line that came with it
On October 20 I moved Elasticsearch to a self-hosted Linux machine outside Azure and connected it through a small WireGuard VM in Azure. The compute line went to zero. The egress line on the WireGuard VM went the other way:
- Oct 19: 0.2 GB out
- Oct 21: 36.7 GB
- Oct 22: 66.1 GB
- October bandwidth on that VM: $42.30 (September: $1.35)
Every search query and its response now crossed Azure's metered egress. In 11 days, the tunnel's bandwidth cost more than the Elasticsearch VM's compute did in a full month. It fell back to 3-19 GB a day once the app itself moved (below), but this is a good example of the cost of a move landing on a line item you weren't watching.
Deploys: 9,611 tiny files over SMB
Windows App Service stores your site on an Azure Files (SMB) share. A Next.js standalone bundle for this app is 9,611 files averaging 2.3 KB, 21 MB in total. Extracting them one at a time over SMB took about 10 minutes at best. When the runtime fetch cache had grown to tens of thousands of entries, KuduSync deleted those one at a time too, and deploys hung for an hour. One of them ended in a failed state after 75 minutes.
Switching to run-from-package (WEBSITE_RUN_FROM_PACKAGE pointing at a zip in blob storage) cut the deploy step to about 6 seconds: 2.5 s upload plus 3.3 s restart. The catch is that wwwroot becomes read-only, so Next's on-disk incremental cache stops working. I had to write a filesystem cacheHandler that stores entries in %HOME%\data.
On November 3 I left App Service anyway. hipa.ai now runs as a Linux container behind Caddy on a shared B2as_v2 VM (2 vCPU, 8 GB), with a 768 MiB memory limit. That whole VM, shared with other projects, came to $31.41 for November 1–16: $14.49 compute, $3.37 disk, $10.90 bandwidth, $2.65 private link. That's on pace for about $60 a month for the whole VM, less than the old shared plan alone, and deploys are an image pull and a swap.
The AI bill: the number I can't give you
This is the embarrassing part. I generated articles with three providers for seven months and never logged a single token until October 23, when I added this to the shared generator:
// every generateArticle() call records provider usage and keeps a run total
llmUsage.inputTokens += delta.inputTokens;
llmUsage.outputTokens += delta.outputTokens; // reasoning tokens bill as output
console.log(`[llm] calls=${u.calls} input=${u.inputTokens} ` +
`(cached ${u.cachedInputTokens}) output=${u.outputTokens} cost=$${cost}`);
So I'm not going to quote a cost per article. I'd be making it up. Here's what I can say for sure.
The provider you pick changes output length more than the prompt does. Gemini 2.5 Flash, with the same prompts, kept writing state-level articles of about 400 characters when the target was about 2,000. What fixed it: fetch one existing good article from Mongo and append it to the prompt as a model to follow. With that, Flash wrote full-length pieces about 80% of the time. A retry covers the rest (regenerate if the body is under 800 characters for state articles, or under 1,500 for national ones).
Billing can disappear under you. On July 8 the OpenAI key started returning 429 billing_not_active. My screening and matching jobs talk to an OpenAI-shaped client, so the fallback took four environment variables and no code:
$env:OPENAI_API_KEY = $geminiKey
$env:OPENAI_BASE_URL = 'https://generativelanguage.googleapis.com/v1beta/openai'
$env:MATCHING_FACTS_MODEL = 'gemini-2.5-flash'
$env:MATCHING_FACTS_REASONING_EFFORT = 'none' # Gemini rejects reasoning_effort
If your LLM calls go through one provider-agnostic client, a billing outage costs an env change instead of a rewrite.
Order your pipeline so a failure can't waste tokens. One weekly run published 23 state articles whose infographics returned 404. The rule now is: render the PNG from the stats (deterministic, no tokens), upload it, then call the LLM, then upsert. A failed upload aborts before any tokens are spent. Every rerun skips docs that already exist, so it never pays twice for the same article.
The expense that never showed up on an invoice
On July 16, 2026, Google search traffic dropped about 92% in one day, across every section of the site at once. Clicks went from 1,368/day to about 50, and impressions from 59K/day to about 5K. Positions for the queries we still showed up for didn't move (median 5.0 → 5.0). We just showed up for 87% fewer queries. There was no manual action. It looks like an algorithmic classifier reacting to a site with tens of thousands of programmatically generated pages.
By late October I had noindexed the drug and condition update posts and paused their generation. I put that on the cost sheet too, because it's the biggest cost on it: the LLM spend I didn't measure was almost certainly smaller than the traffic it ended up costing.
What I'd tell myself in March
- Log tokens from the first call. It's about twenty lines of code.
- Watch bandwidth. On a small site it can beat storage and secrets combined, and most of it may be bots.
-
Give stateful services room (RAM headroom, swap,
Restart=on-failure) before you need them. - Shared infrastructure hides unit costs. It's cheap, but you won't know what one project costs.
- Treat scaled content as a risk on the balance sheet. The cheapest article to generate can be the most expensive one to publish.
If you want to see what all this is serving, it's hipa.ai: search recruiting clinical trials by condition and city.
Oleksandr Gamaniuk
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.