Scrivio Interview library
DesignPrincipal6 min read · updated 12 November 2026

Static factories and service providers (for example JDBC drivers and XML parser factories found through ServiceLoader) underpin pluggability in the JDK. When designing an internal platform meant to last ten years, how do you decide what to make pluggable through factories and what to keep fixed?

I treat every extension point as a long-term compatibility promise, so I add one only where several real implementations exist or are planned, and keep everything else fixed. Where I do expose creation, I use static factories and interfaces, so implementation classes can change without breaking callers, as List.of returns hidden classes. Implementations live in internal packages, and with modules, provides and uses declarations make providers explicit. Finally, I measure how each extension point is used and deprecate unused ones with a long notice period.

Why this question is asked

A platform that lasts ten years outlives several generations of its own code, its teams and its users' expectations. The JDK is the best example we have: JDBC drivers written for Java 6 still load through ServiceLoader, and code that called DocumentBuilderFactory.newInstance() in 2005 still works. That longevity came from careful choices about what to make pluggable and what to keep fixed. Interviewers ask this at the highest levels to see whether we think of API surface as a liability as well as an asset. In this answer, we will recall how the JDK makes things pluggable, see why each extension point is a promise, decide what deserves one, hide implementations behind factories and modules, and plan how to retire extension points over time.

1How the JDK Makes Things Pluggable

The JDK uses two related tools. A static factory, such as List.of or HttpClient.newHttpClient(), returns an interface type and hides the implementation class, so the JDK can change that class in any release. A service provider mechanism, ServiceLoader, lets separate jars supply implementations of an interface: JDBC drivers register themselves as java.sql.Driver providers, and the XML factories such as DocumentBuilderFactory look for a provider before falling back to the built-in one.

Both tools separate what callers depend on, an interface and a way to obtain an instance, from what implementers provide. That separation is what lets an ecosystem grow without breaking its users, but it also creates obligations that the JDK has carried for decades.

2Every Extension Point Is a Compatibility Promise

Once an interface is open for others to implement, every method on it is frozen in a way that a fixed class is not. Adding a method breaks every existing implementation unless it has a default, removing one breaks callers, and changing the meaning of a method breaks both in subtle ways. Implementers will also rely on behaviour we never documented, such as the order in which callbacks are called. Over ten years, with dozens of teams implementing an interface, every one of these becomes a migration project.

So the cost of an extension point is not the day we add it; it is every day after. A good rule is to add one only when there are already two real implementations, or a concrete, funded plan for a second. A hypothetical future provider is not enough, because the interface we design for it today will be wrong in ways we cannot predict, and then we will be stuck supporting it.

Pluggable or fixed?
SignalLean pluggableLean fixed
Implementations todayTwo or more real onesOne
Who implementsOther teams or customersOnly the platform team
Rate of change of the contractStable, well understoodStill evolving
Cost if wrongLow, few implementersHigh, many implementers
Example in a platformStorage backends, auth providersInternal retry logic, metrics naming
An extension point we can add later is cheaper than one we must remove later.

3Static Factories Keep Implementations Replaceable

Where creation must be part of the public API, static factories returning interfaces give us room to change. Callers depend on the interface and the factory method, never on a concrete class, so we can replace the implementation, split it into several, or return specialised versions for particular inputs, the way List.of returns different hidden classes for different sizes.

Java
// Public API package: com.acme.platform.ratelimit
public interface RateLimiter {
boolean tryAcquire(String key);
static RateLimiter perSecond(int permits) {
return permits <= 100
? new SmallTokenBucket(permits) // internal class, can change any release
: new ShardedTokenBucket(permits); // internal class, added in version 3
}
}
RateLimiter limiter = RateLimiter.perSecond(50); // callers never name a class

Notice that RateLimiter here is pluggable for callers in one direction only: they can obtain and use limiters, but the factory decides the implementation. Whether outside teams may also implement RateLimiter is a separate decision, and often the answer should be no; we can document the interface as not intended for implementation, or use a sealed interface to enforce it.

4Hiding Implementations With Packages and Modules

A factory only protects us if callers cannot reach around it. Plain packages are a weak barrier: a public class in an internal package is still usable by anyone. The Java module system makes the barrier real. A module exports only its API packages, so internal packages are inaccessible at compile time and run time, and service providers are declared explicitly rather than found by scanning.

Java
// Platform API module
module com.acme.platform {
exports com.acme.platform.storage; // interfaces and factories only
uses com.acme.platform.storage.StorageProvider;
}
// A provider module from another team
module com.acme.storage.s3 {
requires com.acme.platform;
provides com.acme.platform.storage.StorageProvider
with com.acme.storage.s3.internal.S3StorageProvider; // not exported
}

The uses and provides clauses make the plugin structure visible in the code: a reader, a tool or a reviewer can see which modules consume a service and which provide it, instead of discovering it from files under META-INF/services. For codebases that are not modular, the same discipline can be approximated with internal package naming conventions and ArchUnit rules that forbid dependencies on internal packages.

5Measuring and Retiring Extension Points

Extension points that nobody uses still cost us: they must be documented, tested and kept compatible. So we measure. The platform can log or count, at startup, which providers are loaded for each service interface, and a quarterly report shows which extension points have zero, one or many implementations in real use.

An extension point with no external implementations after a year or two is a candidate for removal. Removal follows the JDK's own discipline: mark it deprecated, explain the replacement, keep it working for a long notice period, for example two major versions or a year, warn at startup when it is used, and only then remove it. Long-lived platforms earn trust by making breaking changes rare, announced and boring.

Step throughLife cycle of an extension point
  1. Proposedneeds two real implementations or a funded plan
  2. Addedinterface plus static factory, internal implementations
  3. Measuredproviders loaded per service, reported quarterly
  4. Still used?
    YesKeep, evolve with default methodsNoDeprecate with notice
  5. Removedafter the notice period and migration support

5 steps in order. Play them, or step through them one at a time.

6Follow-up questions

How do you evolve an interface that others implement?

Add new methods as default methods with sensible behaviour, so existing implementations keep compiling and working. Never change the meaning of an existing method; add a new one instead and deprecate the old. For bigger changes, introduce a second interface version and support both for a notice period.

Is ServiceLoader still a good choice with Spring?

Inside a Spring application, beans are usually the simpler extension mechanism, because providers can have dependencies injected. ServiceLoader is better for libraries that must work without Spring or for plugins discovered from separate jars, and many frameworks, including Spring Boot's own auto-configuration mechanism, use a similar file-based discovery idea.

What is the risk of making everything fixed?

Teams that need a variation will copy code or fork the platform, which is worse than a well-designed extension point. The goal is not zero extension points, but extension points where real variation exists, designed from real implementations.

7Conclusion

In this answer, we saw that every extension point in a long-lived platform is a compatibility promise paid for every year, so we add one only where several real implementations exist or are planned. Static factories returning interfaces let implementation classes change freely, internal packages and module exports with provides and uses keep implementations hidden and providers explicit, and measurement plus long, announced deprecations retire extension points that nobody uses.

What to say in the interviewAbout 80 seconds aloud

Open with

My starting point is that every extension point is a compatibility promise. Once other teams implement an interface, every method on it is effectively frozen, and over ten years that turns into migration projects.

Then, if they want more

So I would only make something pluggable where there are already two real implementations, or a concrete, funded plan for a second one, and keep everything else fixed, because adding an extension point later is cheaper than removing one.

Where creation is part of the API, I would use static factories that return interfaces, like the JDK does with List.of, which returns hidden classes that changed between releases without breaking anyone. That lets us swap or specialise implementations freely.

Implementations live in internal packages, and if we use modules, only API packages are exported, and plugin structure is explicit through uses and provides declarations, which makes it visible to readers and tools, unlike scanning META-INF services files. For non-modular code I would enforce the same boundary with ArchUnit.

Then I would measure which providers are actually loaded in production, and for extension points nobody uses, deprecate them with a long notice period, warn at startup, and remove them only after migration support. Default methods are the tool for evolving interfaces that stay.

About this answer

Last updated
12 November 2026
Versions it names
Java 6
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 "Static factories and service providers (for example JDBC drivers and XML parser...": https://scrivio-interview-library.netlify.app/java/creational-patterns/228082eb63/