A backend can become hard to change without any single decision looking particularly bad. A controller picks up a business rule. A service starts depending on a storage provider’s request types. Before long, changing one behaviour means following those assumptions through several files.
That’s why I care about boundaries. I want to be able to look at a part of a system and understand its responsibility, its dependencies, and what another part can expect from it.
A file-storage service is a useful example of how I think about this.
Start with the job
I like to describe the work in a sentence before deciding where the classes should go:
Take a file, store its contents, and give the caller a reference they can use to retrieve it.
There are already decisions to make here. Where will the bytes live? How will references be generated? Will the caller send the file over HTTP? I try to keep those questions separate from the behaviour the application needs.
A local filesystem may be enough at first. An object store may make more sense once the application runs elsewhere. If the caller’s expectations stay the same, changing the storage mechanism should require as little work outside the storage code as possible.
Give each decision a home
The split I find useful is between things that change for different reasons. A rule about which files are allowed belongs with the application’s rules. Credentials and provider requests belong with the code that talks to the storage system.
A small interface can express the capability the rest of the application needs:
public interface ContentStore {
BlobReference store(InputStream content);
InputStream retrieve(BlobReference reference);
}
What matters to me is what this interface asks callers to understand. They need a stream and a reference. They don’t need a bucket name, a connection string, or an SDK request object.
An interface only helps if it keeps those details contained. If every caller still has to understand the provider, the extra abstraction hasn’t bought much.
I use names to reinforce that separation. ContentStore describes a capability. A provider-specific name can be useful inside the adapter, where that detail actually matters.
Make failure part of the contract
The two methods above leave plenty unanswered. Before relying on them, I’d want to know:
- How does retrieval fail when a reference doesn’t exist?
- If a store operation is retried, can it create another copy?
- After a timeout, could the file already have been stored?
- Who is responsible for closing each stream?
These details affect the caller’s code just as much as the return type does. They determine whether a retry is safe and what recovery is possible.
I prefer making those expectations explicit in the contract and its tests. Otherwise, each caller ends up inventing an answer, and the same operation starts behaving differently across the application.
Keep the design proportional
I don’t think every responsibility needs its own project or service. Sometimes a few classes with clear names and dependencies are enough.
When I’m deciding where something belongs, these are the questions I come back to:
| Question | Where I’d start |
|---|---|
| What makes an operation valid? | Business rules |
| What work needs to happen for this request? | Application logic |
| How do we talk to a database or storage provider? | Infrastructure adapter |
| How does a client send a request and receive a response? | Delivery code |
Those are responsibilities to keep understandable. They can live in the same application. I’d add another layer when it gives a decision a clearer home or makes behaviour easier to check.
Test the promise
For a content store, I care that storing bytes and retrieving them gives the caller the same bytes back. I also care that an unknown reference produces the failure the contract describes.
Those checks remain useful if the adapter changes. A test that depends on every internal method call is more likely to need rewriting alongside the implementation.
Where adapters share a contract, I’d run the same behavioural checks against each one. Any differences in guarantees need to be visible, especially around retries and failure. A common interface shouldn’t hide a difference the caller needs to handle.
Leave room for the next change
I’m not trying to design for every storage provider or requirement that might appear. I want the current decisions to be clear enough that the next change has an obvious place to go.
That’s the test I keep coming back to: can someone understand what this part does, what it depends on, and what it guarantees without tracing the whole application?
If the boundary helps answer those questions, it’s doing useful work.