A Java server for one dollar per month

If you build apps on your own, you know the drill. You have more ideas than time, most of them won’t work, and you won’t know which ones until real people use them. So you need to ship fast and spend almost nothing on each try. And every so often you read about a developer who woke up to a cloud bill bigger than their app will ever earn.

This week a Codename One backend got small enough to change that math. Five of them run side by side in 1 GB of memory and one CPU, the size of Linode’s $5 Nanode and of Hetzner’s entry plans. We measured it in a container capped at exactly that. Each one idles at 20 to 23 MB. That’s a Java backend for a dollar a month per app, and a bill that never moves.

Java has a reputation for being expensive to host. That comes from decisions the JVM’s authors made long ago, a big runtime, a heap sized up front, a warmup before it runs fast, and none of it is inherent in Java the language. Our backend is your Java code compiled to a native executable, so it doesn’t carry any of it.

TL;DR

Coming This Week

  • Saturday, December 5: Faster Reads the Build Won't Let You Break, and gRPC for Your Java Backend. Read-only transactions, gRPC in all four shapes, GraphQL, IMAP and more.
  • Sunday, December 6: Build a Side Scroller Your Server Can Replay Frame for Frame. A fixed point platformer engine with cheat-proof leaderboards.
  • Monday, December 7: Turn Your Figma, Sketch or HTML Design Into Working Forms. With a workbench, or with your agent.
  • Tuesday, December 8: Review the 30,000 Lines Your Agent Wrote Without Reading Them Top to Bottom. Charts, call graphs and flowcharts, with the agent walking you through them.
  • Wednesday, December 9: Launch Your Own Language Tutoring App With AI and Human Teachers. Lingo, a complete template.
  • Thursday, December 10: Twenty New Components You Won't Have to Write Yourself. Swipe decks, slide to pay, card fields, step flows and more.
Hollowdeep, an exploration platformer with a minimap
Hollowdeep.
The Code Visualizer change graph with new and modified classes
The change graph.
The Design Import workbench next to the source design
Design Import.
Lingo scoring a spoken phrase word by word
Lingo.

Two choices for a new app

When you start an app today you pick one of two roads for the backend.

The first is a serverless platform: Firebase, Supabase, Lambda. Nothing to run, a free tier to start on, and a price that follows your traffic. The second is a server of your own. It used to be the expensive road for Java, because each app wanted a machine sized for its JVM. At 20 MB per backend, five apps share one $5 box, so that road now starts at about a dollar a month per app.

So the price of starting is close to even. What’s left is the difference between the two bills when something happens:

flowchart TB A[Your app gets noticed] --> S[Serverless] A --> O[Your own $5 server] S --> S1[Every request is billed] S1 --> S2[The invoice grows with the traffic] O --> O1[The CPU fills up] O1 --> O2[Requests get slower for a while] O2 --> O3[The bill stays $5]

A serverless bill depends on traffic you don’t control: a post that goes viral, a bot that crawls your API, a bug in your own client that retries in a loop. A small server can degrade, but it can’t bankrupt you. For an indie developer that’s the whole question. I’ll take a slow afternoon over a surprise invoice every time, and I suspect so would the people who’ve shut down an app over a cloud bill.

Both roads are fully supported in Codename One, and both are covered below. But if you want a number you can put in a spreadsheet, it’s the server.

Five backends, one small box

A Codename One backend is your Java code, translated to C and compiled into one native Linux executable. There’s no JVM, no warmup, and no heap sized for a worst case.

We measured our sample apps on SQLite inside a container limited to 1 GB of memory and one CPU, with every simulated user signing in, opening the main screens and saving something, then pausing three to eight seconds before the next request. That pause is what real people do, and leaving it out is how benchmarks lie.

What ranMemoryResult
One small backend, idle20-23 MB
Six backends, idle160 MB
Six backends, 50 active users each710 MB peak3 failures in 10,000 requests
Six backends, 100 active users eachover 1 GBCPU saturated, one backend killed
One storefront, 52 stores, 1,560 products, 120 shoppers360 MBproduct pages under 60 ms

The test core was a fast laptop core, and a cloud host’s shared core is usually slower. So we say five, not six. A few dozen users active at the same moment is an app with hundreds or thousands of installs, which is more than most new apps ever see.

The CPU runs out before the memory does, which is the right way around. An overloaded box gets slower before it falls over, and the guide adds a swap file so a burst turns into a slow minute instead of a killed process.

Most Java servers in the wild are far bigger than their traffic. Datadog’s State of Java report found that 52% of the Java web services it monitors handle fewer than one request per second at their busiest hour, and only 7% handle more than 100. Your new app is almost certainly in the first group. It deserves a server sized for it.

flowchart LR I[Internet] --> C[Caddy
HTTPS for every host name] C -->|shop.example.com| A[shop
~20 MB] C -->|tutor.example.com| B[tutor
~20 MB] C -->|game.example.com| G[game
~20 MB] C -->|crm.example.com| D[crm
~20 MB] C -->|blog.example.com| E[blog
~20 MB] A --- AD[(shop.db)] B --- BD[(tutor.db)] G --- GD[(game.db)] D --- DD[(crm.db)] E --- ED[(blog.db)]

The setup in Several apps on one small server is plain processes, not containers. Plain processes share memory, so the app that gets busy for five minutes borrows from the four that are asleep. One systemd unit file serves every app:

# /etc/systemd/system/[email protected]
[Service]
DynamicUser=yes
StateDirectory=%i
WorkingDirectory=/opt/%i/current
EnvironmentFile=/etc/%i/env
ExecStart=/opt/%i/current/%i
Restart=on-failure

Each app gets a two line environment file with its port and its database, PORT=8081 and DATABASE_URL=sqlite:/var/lib/shop/shop.db. Enable it by name, systemctl enable --now cn1app@shop, and Caddy routes its host name and gets its certificate. Back up each SQLite file nightly with sqlite3 ... ".backup" and ship the copy off the machine.

Your agent runs the server

The real reason indie developers pick serverless isn’t the price. It’s that running a server sounds like a second job: Linux, TLS certificates, deploy scripts, rollbacks. That used to be true. Now it’s a job for your coding agent.

Every project from the Initializr ships an agent skill, and its deployment reference walks the agent through the whole thing. It starts by asking you the four things only you know: where it runs, the domain, the database, and which clients ship. It tells you plainly which steps only you can do, like paying the provider and setting DNS. Then it does the rest with copy-ready templates:

TemplateWhat it does
build-linux.shPackages the backend for Linux inside a Podman or Docker container, so a Mac can build the binary a Linux server runs
server-setup.shPrepares the server once, with a separate user to run the app and one to deploy it
myapp.service and env.exampleThe systemd unit, and secrets kept on the server, never in git
CaddyfileHTTPS with automatic certificates
deploy.sh and rollback.shA release, and the way back when one goes wrong
deploy.ymlOptional GitHub Actions, so every push to main redeploys

The skill also knows the traps that eat an evening. The backend compiles for the machine it runs on, so a Mac produces a Mac binary, and the skill packages inside a Linux container or on a Linux CI runner instead. The binary links against the system’s OpenSSL, so it builds on the same distribution the server runs and checks with ldd that nothing is missing. And it verifies the deployment before it reports success, then switches your apps to the HTTPS address.

So in practice you rent a $5 server, give your agent SSH access and a domain, and say “deploy this.” When a second app is ready, it goes on the same box.

What a busy month costs

AWS Lambda’s free tier is a million requests and 400,000 GB-seconds a month. That sounds like a lot. A million requests over a 30 day month is 0.39 requests per second.

So let’s price the box we just measured. Six backends with 50 active users each, pausing three to eight seconds between requests, is about 50 requests per second, and the box handled it with 3 failures in 10,000. Kept up all month, that’s about 130 million requests. On Lambda, at AWS’s published x86 rates, with a modest 512 MB Java function averaging 100 ms:

ItemMathMonthly
Requests129M billable x $0.20 per million$26
Compute(6.5M GB-s - 400k free) x $0.0000166667$101
HTTP API Gateway in front130M x $1.00 per million$130
Totalabout $257
The server$5

You won’t run at peak all month, and Lambda’s bill will shrink when you don’t. That’s the point of it. But you don’t get to choose the month. The box has over a hundred times the free tier’s capacity sitting there for the day somebody posts your app on Reddit, and its price never moves.

Lambda still has its place. Our backend ships LambdaRuntime for exactly that reason, and if you need to scale to zero across forty regions, use it.

If you pick serverless

Some apps belong on a serverless platform from day one, and some developers simply prefer it. For them, Codename One now talks to both Firebase and Supabase directly, over REST, on iOS, Android, desktop and the web. There’s no native SDK to wire into each platform, so the same code runs everywhere.

Supabase supabase = new Supabase("https://xyzcompany.supabase.co", "public-anon-key");
supabase.from("messages").select("id,body,author")
        .eq("room", "general").order("id", false).limit(50)
        .execute().ready(rows -> showMessages(rows));

supabase.realtime().channel("room1")
        .onPostgresChanges("INSERT", "public", "messages", null, change -> addMessage(change))
        .subscribe();

Supabase brings auth, Postgres queries through PostgREST, storage buckets and live channels. com.codename1.cloud.firebase covers Firestore documents, queries, batched writes and live snapshot listeners, Firebase Storage with resumable uploads, Auth, and Remote Config:

Firestore db = new Firestore("my-project");
db.setTokenProvider(authTokens);
Map<String, Object> city = new HashMap<>();
city.put("name", "Tel Aviv");
db.set("cities/tlv", city).ready(doc -> Log.p("Saved " + doc));

Set a budget alert on day one. If the bill ever starts to worry you, your client is already Java, and moving to your own backend swaps only the data calls.

Knowing when an app has outgrown the box

A $5 server won’t hold every app forever, and you shouldn’t have to guess when it’s full. The developer guide spells out the signals in Knowing when an app has outgrown it. Move something when any of these holds for days, not minutes:

  • Load stays above 0.7 at the busy hour on a one CPU server.
  • CPU steal stays above 10%, which means the host itself is short.
  • Available memory stays under 150 MB, or the server swaps at the busy hour.
  • An app has requests waiting for a database connection.
  • The kernel has killed a process.

A five minute cron script in the guide logs every one of those per app, so you know which app grew. When one grows, move that one: lower the DNS time to live a day ahead, stop it, copy its database file, start it on the new server. A minute of downtime. When they all grow, resize the box, which every provider does in minutes with the same address and disk. Either way, you decide when to spend more, and only once your users are paying you.

The fine print

SQLite writes one transaction at a time, and five apps on one box is one machine that can fail. For the apps in this post that’s the right trade: a nightly backup and a one minute restore beat a cluster nobody needs. When one app needs several servers behind a load balancer, the same code runs on PostgreSQL or MySQL, and the guide covers that move too. The backend’s class library is the Codename One runtime rather than all of Java SE, so not every server library on Maven Central will translate. What you get in exchange is the 20 MB.

More This Week

Faster reads, enforced by the build

@Transactional(readOnly = true) now skips the flush that runs before every query. The catch with read-only transactions has always been that SQLite ignores the flag, so code that writes by mistake passes every test and fails on the first PostgreSQL deployment. The build now follows every call a read-only method makes through your code and fails when it can reach a write operation:

@Transactional(readOnly = true) CartService.view reaches a write, which
PostgreSQL and MySQL reject in a read-only transaction: ... Mark the method
read-write, or call the write through a REQUIRES_NEW method.

The same release adds gRPC in all four call shapes, server and client, generated from your .proto files, plus GraphQL handlers, @PreAuthorize expressions compiled to plain Java, Argon2 and scrypt password hashes, IMAP, POP3 and DKIM, and Flyway undo and callbacks. Saturday’s article has the details.

A platformer engine that never uses a float

com.codename1.gaming.platformer is a new 2D and 2.5D side scroller engine in core. It’s deterministic: 16.16 fixed point math, a fixed 60 ticks per second and a seeded random generator. That’s what lets the server replay a player’s run tick for tick from 10 bits of input per frame and reject a fake high score. Levels are plain text, one character per tile. In this slice of a level, # is solid ground, = a platform you can jump up through, H a ladder and ^ spikes, so you can see the ladders and the spikes before you ever run it:

"............................=======.....H.................H...",
"................=====...................H#################H...",
"######################.......##########.............########..",
"######################^^^^^^^##########.............########^^",

Download the ghost race video.

Sunday’s article explains why we built a second game engine next to the gaming API, and shows the four games built on it.

Design files become forms

mvn cn1:import-design turns a Figma link, a .fig or Sketch file, a PSD, an SVG or a React or HTML prototype into a Codename One form: a generated base class, a subclass you own, a stylesheet and a unit test. You review it in a workbench, or let your agent drive the same steps through MCP tools. It isn’t a language model guessing at your design: the import is deterministic, and every guess it makes is listed as an issue. Monday’s article walks through it.

Download the Design Import tour.

Review agent code with pictures

Your agent just changed 120 files. Ask it to walk you through them, and it opens the Code Visualizer and connects to it: a window that shows where the change is, which methods matter most, and a before and after flowchart of each one. Click Ask on any box or line and your agent explains it right there, step by step. The charts come from the Java compiler, not a model, so the agent explains what was measured rather than guessing at it. Tuesday’s article shows a real review.

The Code Visualizer highlights view with before and after flowcharts

Lingo, a tutoring business in a template

Lingo is a language learning app with an AI tutor that can run on the phone, pronunciation scored word by word, teachers who publish courses and teach live classes, and certificates anyone can verify. It’s a template in the Initializr, MIT-0 licensed.

Download the Lingo lesson video.

Wednesday’s article has the tour.

Twenty components you won’t have to write

Core gained SwipeDeck, SlideToConfirm, CreditCardField, CountryPicker, RatingBar, CircularSlider, StepFlow, AvatarGroup, Confetti and eleven more, the pieces most apps end up writing by hand. Thursday’s article shows the ones worth reaching for first.

A checkout step flow and input components on iOS

A cleaner skins menu, with 49 devices built in

The simulator’s skins menu used to be a pile. It’s now grouped into Phone, Tablet, Watch and Desktop, and ships 49 device skins out of the box: 10 iPhones, 10 Android phones, 5 foldables, 10 iPads, 10 Android tablets and 4 watches, plus Mac, Windows and Linux desktop frames. Every skin is drawn in code from the device’s screen size, density, cutout, safe areas and hinge, so there’s nothing to download and nothing to go stale. Your own skins and the Skin Designer sit right under the built-in groups.

The 49 built-in simulator skins: phones, foldables, tablets and watches

StoreKit 2, opt-in

iOS and Mac builds can now use StoreKit 2 with one build hint:

codename1.arg.ios.storeKit2=true

Your purchase code doesn’t change. Purchase and the callbacks you already use work as before, and two new callbacks report Ask to Buy approvals and refunds. Transactions are verified on the device, and one isn’t finished until its receipt is saved. One thing does change: Receipt.getOrderData() becomes a signed JWS transaction instead of the old base64 receipt, and Apple’s deprecated verifyReceipt endpoint rejects it. If your server validates receipts that way, move it to JWS or App Store Server API verification first. Commerce accepts both already. Apple adds new features only to StoreKit 2, so plan on turning it on. StoreKit 2 on iOS and macOS in the developer guide covers the switch and testing with StoreKit configuration files.

Pick the bill you can live with

Moving fast and paying little were never the hard part. Paying little and knowing you’ll keep paying little was. A dollar a month on a box you control gives you that, and your agent can set it up for you. Generate a backend project from the Initializr, point your agent at our llms.txt, and ship five ideas this month for less than the price of a coffee. Tomorrow: faster reads and gRPC.