Quick revision
The short answer
Stateless by default does not mean state disappears; it means state leaves the service instance and goes to a home built for it. Sessions go to a shared session store or into tokens, files go to object storage with signed URLs, work in progress goes to queues and durable workflow state rather than memory, and coordination such as locks and leader election goes through a supported store. The platform documents which store to use for which need and provides each one as an operated service, so teams do not build their own.
What to remember
In this answer, we saw that stateless by default means state moves to homes built for it. Sessions go to a shared session store or tokens, files to object storage with signed URLs, work in progress to queues and durable workflow state, and coordination to locks and leader election through a supported store. The platform documents which store fits which need and operates each one, so following the standard is easier than working around it.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Stateless by default does not mean state disappears; it means state leaves the service instance and goes to a home built for it. Sessions go to a shared session store or into tokens, files go to object storage with signed URLs, work in progress goes to queues and durable workflow state rather than memory, and coordination such as locks and leader election goes through a supported store. The platform documents which store to use for which need and provides each one as an operated service, so teams do not build their own.
Why this question is asked
A rule like 'every service must be stateless' is easy to write and hard to follow, because every real service has state somewhere. If the platform only states the rule, teams invent their own answers: one runs Redis in a sidecar, another writes files to a shared volume, a third keeps a job queue in memory. Interviewers ask this design question to see whether we can name the kinds of state that remain and turn them into a small menu of supported services. In this answer, we will recap what stateless means for the platform, then go through sessions, files, work in progress and coordination, and finish with how to document and operate the menu.
1A Quick Recap: Stateless Instances, Stateful Systems
A stateless service instance keeps nothing that a later request depends on in its own memory or local disk. That is what lets the platform start, stop and move instances freely, autoscale them and replace them during deployments. The system as a whole still has plenty of state; it just lives in stores designed to outlive instances.
So the platform's real job is to provide those stores. Each kind of state has different needs, for durability, latency, size and consistency, which is why one store does not fit all of them.
| Kind of state | Standard home | Platform service |
|---|---|---|
| User sessions | shared session store or tokens | managed Redis, identity service |
| Files and blobs | object storage, signed URLs | managed bucket with lifecycle rules |
| Work in progress | queues, durable workflow state | managed broker, workflow engine |
| Coordination | locks, leader election | supported store with a client library |
| Business data | the service's own database | managed PostgreSQL |
2Sessions: A Shared Store or Tokens
Web applications need to remember who the user is between requests. The platform offers two patterns. The first is a managed Redis cluster with Spring Session configured by the platform starter, so HttpSession works unchanged and sessions survive any instance. The second is token-based authentication: an identity service issues short-lived signed tokens, and every service verifies them without a shared store.
The standard says which to use when. Browser applications that need server-side session data, such as a multi-step form, use the session store with small, serializable attributes. APIs called by other services or mobile apps use tokens. Either way, no service keeps sessions in its own memory.
3Files: Object Storage With Signed URLs
Uploads, generated reports and images go to object storage. The platform provides buckets per service with access rules, encryption, lifecycle rules that delete or archive old objects, and a client in the starter. The database stores only the object key.
Large files should not pass through service instances at all. The service creates a signed URL, a link that allows one upload or download for a few minutes, and the client transfers the bytes directly to storage. That keeps instance memory and bandwidth free and avoids timeouts on large transfers.
4Work in Progress: Queues and Durable Workflows
This is the state teams most often forget. A service that accepts a request, keeps a task in an in-memory list and processes it later loses that task when the instance stops. A multi-step process, such as 'reserve stock, charge card, ship', that keeps its progress in local variables cannot resume after a restart.
The platform provides a managed message broker, such as Kafka or RabbitMQ, for work that can be processed independently, and a durable workflow engine, or at least a documented pattern for storing workflow state in the database, for long multi-step processes. The rule is that accepted work is written to durable storage before we acknowledge it, so a crash means a retry, not a loss.
- Request arrivesfor example generate a report
- Write a task to the queue or tabledurable before we answer
- Answer 202 Accepted with a task id
- Any instance picks up the taskconsumer group or job table
- Instance dies mid-task?YesTask is redelivered or resumedNoMark the task done
5 steps in order. Play them, or step through them one at a time.
5Coordination: Locks and Leader Election
Some work must happen in only one place at a time: a nightly job, a sequence that hands out invoice numbers, a single consumer of an external feed. With many interchangeable instances, they need a way to agree. The platform supports one or two mechanisms with client libraries in the starter, for example database-backed locks with ShedLock for scheduled jobs, and leader election through Kubernetes leases or a coordination store for long-running single-active workers.
The important word is supported. Distributed locks are easy to get subtly wrong, for example a lock that expires while its holder is paused in garbage collection, so teams should use a library the platform has tested, with documented guarantees, rather than writing their own SETNX loop.
6Document the Menu and Operate It
The last part is what makes the standard work: a short, documented decision guide that says, for each need, which store to use, with a link to the operated service and an example in the template. A team asking 'where do I put an upload' should find the answer in a minute.
Behind each entry is a service the platform operates: provisioning through self-service, backups, monitoring, upgrades and on-call. If teams must run their own Redis to follow the standard, they will either skip the standard or run Redis badly. We also review exceptions, for example a service that needs a local cache, and add new entries when several teams ask for the same thing.
7Follow-up questions
Are local caches allowed in a stateless service?
Yes, as long as losing them is harmless and instances may briefly disagree. A cache of reference data with a short expiry is fine; the instance can rebuild it after a restart. What is not allowed is state that only exists in that cache, or data that must be identical across instances without an invalidation mechanism.
Why not let each team choose its own stores?
Because every store is operational work: backups, upgrades, security patches, monitoring and on-call. Twenty teams running twenty Redis setups means twenty sets of mistakes. A small menu of operated services gives teams speed and reliability, and the platform can still add options when needs are real.
How does the platform enforce statelessness?
Mostly by making it the easy path, then by testing it. Read-only root filesystems in containers stop accidental local writes, the template uses the supported stores, and regular chaos tests that kill pods reveal state that was kept in memory.
8Conclusion
In this answer, we saw that stateless by default means state moves to homes built for it. Sessions go to a shared session store or tokens, files to object storage with signed URLs, work in progress to queues and durable workflow state, and coordination to locks and leader election through a supported store. The platform documents which store fits which need and operates each one, so following the standard is easier than working around it.
Open with
Stateless by default means instances keep nothing that later requests depend on, so the platform's real job is to give each kind of state a supported home. Sessions go either to a managed Redis with Spring Session preconfigured in the starter, for browser apps that need server-side session data, or to short-lived signed tokens from an identity service for APIs.
Then, if they want more
Files go to object storage with per-service buckets, encryption and lifecycle rules, and big transfers use signed URLs so bytes never pass through pods.
Work in progress is the one teams forget: accepted work must be durable before we acknowledge it, so the platform offers a managed broker for independent tasks and a workflow engine or a documented database pattern for multi-step processes, so a crash means a retry, not a loss.
Coordination, like single-run jobs and leader election, goes through supported mechanisms such as ShedLock on the database or Kubernetes leases, because hand-written distributed locks are easy to get wrong.
Finally I would publish a one-page decision guide mapping each need to its store, with examples in the template, and make sure the platform actually operates every service on it, backups, monitoring and on-call, otherwise teams will work around the standard.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A platform team wants every new service to be stateless by default. Which kinds of state...": https://scrivio-interview-library.netlify.app/spring-boot/scalability/2931b8a839/