response streaming.md
Host ai workflow runner with Spring Boot: streamed responses
Summary
Deploy an AI workflow runner built with Spring Boot on Ample using the streaming response service pattern. Compute runs the app in an isolated microVM behind a public HTTPS URL, with a managed PostgreSQL 16 database auto-provisioned and injected as DATABASE_URL. Verified on Spring Boot: a Server-Sent Events endpoint read incrementally through the public HTTPS gateway, with five one-second chunks arrived spread over time. This confirmed a 70-second stream of 36 chunks, which surpassed common 60-second idle timeouts and observed a client disconnect after two chunks (disconnected=true).
Infrastructure requirements
- Compute: verified (Apps run in isolated x86_64 Firecracker microVMs that auto-pause when idle and wake on request; sizes are the priced VM sizes.)
- Postgres: verified (Managed PostgreSQL 16 runs in its own microVM and is auto-provisioned when an app needs a database and no DATABASE_URL is supplied.)
Prerequisites
- A Spring Boot project that builds and starts with documented commands (./mvnw -q -DskipTests package or the Gradle wrapper).
- A PostgreSQL driver reading DATABASE_URL at runtime (auto-provisioned when omitted, or supplied with --env).
- An Ample account token with servers:write, databases:read.
Exact tested configuration
- template:
jvm-21 - runtime:
java - size:
s-1vcpu-2gb - build:
./mvnw -q -DskipTests package - start:
java -jar $(ls target/*.jar | grep -v -- '-plain' | head -n 1)
Steps
- Build and start. Run
./mvnw -q -DskipTests package(or the Gradle wrapper) to produce one application jar, thenjava -jaron the jvm-21 template (Temurin JDK 21) with server.port read from PORT. The server must bind 0.0.0.0 on PORT. - Implement the pattern on PostgreSQL. The fixture's module implements streaming response service: a Server-Sent Events endpoint read incrementally through the public HTTPS gateway, conducting a 70-second stream of 36 chunks. Follow the approach in your schema; ensure migrations are idempotent and run them with --release-command.
- Deploy. Run the synchronous deploy once to read the result:
ample deploy . --name <app-name> --public - Verify. Fetch the live URL and self-test route(s) from the example; run own checks. On failure read
ample logs <deployment_id> --kind buildthen--kind runtime.ample logs <deployment_id> --kind build
Success checks
- App responds on its public URL (
/on the live URL). - Streaming-response-service self-test (
/p/streaming-response-serviceon the live URL).
Limitations
- Verified on the jvm-21 template at s-1vcpu-2gb; other sizes and configurations are not verified.
- Apps auto-pause when idle and wake on the next request; always-on is an operator setting.
Cost estimate
Estimated 10.00 USD per month:
- app server x1
s-1vcpu-1gb: 5.00 USD - managed PostgreSQL database x1
s-1vcpu-1gb: 5.00 USD
Verification evidence
- Successful canary run at revision showing the Spring Boot pattern fixture deployed on Ample.
Execution binding
MCP tool ample_deploy, schema hash 876465fce906da0c, binding state current, required scopes: servers:write, databases:read.