Scrivio Interview library
LeadershipPrincipal6 min read · updated 12 November 2026

Spring made the shared singleton the default unit of application code. What long-term effects did this have on how Java teams design services, and is it still the right default?

Making the shared singleton the default pushed Java teams towards stateless service objects, with state kept in databases, caches and messages, which suits horizontal scaling and request-per-thread servers very well. The price is that thread safety became a hidden requirement of nearly every class. The model also fits virtual threads naturally, and although reactive and actor-style designs handle state differently, stateless singletons remain a sound default.

Why this question is asked

Defaults shape habits more than guidelines do. Because Spring makes every bean a shared singleton unless told otherwise, generations of Java developers have learned to write services in one particular shape. Interviewers ask this question at the most senior level to see whether we can reason about how a framework decision influenced architecture across an industry, and whether we can judge if it still holds with virtual threads and reactive systems. In this answer, we will recap what the default means, look at the good effects, the hidden cost, how it fits current concurrency models, and finally give a judgement.

1A Quick Recap of the Default

In Spring, a bean is a singleton unless we choose another scope. The container creates one instance of each service, repository and controller at startup, and every request thread that calls it uses that same object at the same time. In a typical web service with 200 request threads, a single OrderService instance is being called by up to 200 threads at once.

Before Spring, the dominant model in enterprise Java was EJB, where the container pooled stateless session beans and gave each call its own instance from a pool, and stateful session beans held conversation state per client. Spring's choice was simpler: one plain object, shared, with no pooling and no per-client state in the service.

2The Good Effect: Stateless Services and Horizontal Scaling

A shared object that many threads call is only safe if it holds no per-request state. So the default quietly taught teams to write stateless services: the object holds its dependencies, set once in the constructor, and all data about a particular request travels in method parameters and return values. State that must last, such as orders or sessions, goes to the database, a cache like Redis, or a message broker.

That shape turned out to be exactly what horizontal scaling needs. If no instance holds important state in memory, we can run 3 or 300 copies behind a load balancer, kill any of them at any time, and start new ones without coordination. The twelve-factor and cloud-native movements later named this as a principle, but Spring applications were often already built this way because of the default. It also keeps memory use low and predictable: one instance of each service, not a pool per thread.

Step throughThe shape the singleton default encouraged
  1. Load balancerspreads requests over identical instances
  2. Request threadseach carries its own request data
  3. Singleton servicesstateless; dependencies set once
  4. Shared state storesdatabase, cache, broker hold the state

4 layers, from the top down. Step through them one at a time.

State lives outside the service objects, so instances are interchangeable.

3The Hidden Cost: Thread Safety Everywhere

The same default made thread safety a requirement of almost every class, without saying so. A developer who adds a field to cache the last result, or a SimpleDateFormat field, or a mutable counter, introduces a race condition that tests running on one thread will never see. The bug appears under production load as corrupted values or rare wrong answers.

Java
@Service
class InvoiceNumberer {
private int lastNumber; // shared by every request thread
int next() { return ++lastNumber; } // two threads can both get 42
}
@Service
class SafeInvoiceNumberer {
private final AtomicInteger lastNumber = new AtomicInteger();
int next() { return lastNumber.incrementAndGet(); } // 42, 43: never duplicated
}

In practice, the industry responded with conventions rather than tools: final fields set through constructor injection, immutable value objects, records for data, and code review habits that question any mutable field in a service. These conventions work, but they rely on people knowing why, which is a good reason to teach the reasoning explicitly to new team members.

4How It Fits Virtual Threads, Reactive and Actor Models

Virtual threads, final since Java 21, fit the stateless singleton model very well. A virtual thread per request is still a thread per request, and the shared service is called by many of them, exactly as before, just with far more concurrent requests. The same thread-safety rules apply, and stateless singletons benefit because they need no per-thread resources.

Reactive programming, with Project Reactor and WebFlux, keeps the singletons but changes where request data lives: it flows through the reactive pipeline and the Reactor context rather than through a thread. The services are still stateless singletons, but thread-bound helpers such as ThreadLocal no longer work without explicit propagation. Actor-style models, such as Akka or Orleans-style virtual actors, take a different approach: each actor owns its state and processes one message at a time, so the state can live in memory safely. That suits problems with many long-lived, independent entities, such as a game session or a device twin, where loading the state from a database on every message is too slow.

5Is It Still the Right Default?

For most business services, yes. Most of the work is receiving a request, reading and writing a database, and calling other services, and the stateless singleton handles that with the least machinery. Scaling, deployment and failure recovery all stay simple because instances are interchangeable. Where a part of the system really needs in-memory state, such as a high-rate stream aggregation or an actor-like entity, we should choose a model built for that part, rather than forcing state into singletons with locks.

As a leader, the guidance I would give is to keep stateless singletons as the default, teach thread safety as a basic skill rather than an advanced topic, use static analysis and review to catch mutable fields in beans, and make a deliberate, documented decision whenever a component needs to own state.

6Follow-up questions

Why did Spring not pool service instances like EJB?

Pooling solves a problem that stateless objects do not have. If an object holds no per-request state, one instance can serve every thread, so a pool only adds memory and complexity. Spring's choice relied on services being stateless, and in return it removed the pool sizing and lifecycle questions that EJB applications had to answer.

Does using virtual threads change how we write singleton beans?

Mostly not. The beans should still be stateless and thread-safe. What changes is around them: per-thread caches stored in ThreadLocal lose value, because each virtual thread usually handles one task, and code that holds a monitor during blocking IO can pin the carrier thread on older Java versions; Java 24 removed most synchronized pinning (check your version).

When would you choose a different default in a new system?

When the core problem is long-lived in-memory state with high update rates, such as live game rooms, trading order books or device twins. There, an actor model or a partitioned stateful stream processor fits better, because each piece of state has one owner and is processed one message at a time. Even then, the surrounding services that serve APIs usually remain stateless singletons.

7Conclusion

In this answer, we saw that the shared singleton default steered Java teams to stateless services with state kept in external stores, which made horizontal scaling and disposable instances natural. Its hidden cost is that thread safety became a requirement of nearly every class. The model fits request-per-thread and virtual-thread servers well; reactive and actor-style systems move state handling elsewhere, and actors are better for long-lived in-memory state, but stateless singletons remain a sound default for most business services.

What to say in the interviewAbout 80 seconds aloud

Open with

I think the singleton default had a big and mostly positive effect. Because one instance of each service is shared by all request threads, teams learned to write stateless services: dependencies set once in the constructor, request data passed as parameters, and lasting state in databases, caches or brokers.

Then, if they want more

That turned out to be exactly what horizontal scaling needs, because instances are interchangeable, so we can run many copies and kill or add them freely. The cost is that thread safety became a hidden requirement of almost every class.

A single mutable field in a service, like a counter or a SimpleDateFormat, is a race condition that only appears under load, and we rely on conventions like final fields, immutable values and reviews to avoid it. The model fits thread-per-request and virtual threads naturally, since it is the same model with more threads.

Reactive code keeps stateless singletons but moves request data into the pipeline context, so ThreadLocal tricks break. Actor models are better when there is long-lived in-memory state per entity.

So my view is that stateless singletons remain the right default for business services, as long as we teach thread safety explicitly and choose a stateful model deliberately where it is really needed.

About this answer

Last updated
12 November 2026
Versions it names
Java 21, Java 24
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. 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 "Spring made the shared singleton the default unit of application code. What long-term...": https://scrivio-interview-library.netlify.app/spring-boot/bean-scopes/8b68f3e161/