Service Boundaries and Data Ownership: Cut by Capability, One Owner per Table, and Four Questions Before Anything Leaves
Adding an Urgent priority should not touch four services. Cut Relay by capability, give every table one owner, and let stats keep a small copy fed by events (41 resolved becomes 42). Then the capstone plan: notifications (0 outside files) and search (1) leave the monolith, and the SLA ladder (12 files, inside the ticket transaction) stays.
What you will learn
- Cut services by business capability instead of by layer, and use bounded contexts as a guide
- Test a boundary with three questions and spot the signs of a wrong one
- Keep one owner per table and choose between asking, copying and merging when others need the data
- Decide what leaves a monolith with four questions, three of which the code can answer
Before you start
- What an architect does
- Modular monolith basics
Once you decide to split something, the hard part is not the splitting. It is deciding where the line goes. The goal is simple to say: one change touches one service, and every table has exactly one owner. This article works through it on Relay, the support desk app, and ends with the real plan for which parts of Relay leave the monolith.
One change, four services
A change request: add a new priority, Urgent. It goes into the tickets service, of course. Then the ripple starts. Notifications must show it in emails. Stats must count it. The AI service must understand it. Four services to change, test and release for one small idea. If a service always has to change together with another one, the line is probably in the wrong place.
Cut by what the business does
A helpful idea here is the bounded context: the area where a word has one meaning. In tickets, a customer is a name and an email to reply to. In people, a customer is a login, a role and a password. In notifications, a customer is an email address, a language and quiet hours. Three models of one word, and that is fine. A service boundary often follows a bounded context.
Three tests for a good line
- Do things that change together stay together? Comments and tags change whenever tickets change, so they belong inside tickets.
- Can one team own it from idea to release, without waiting for anybody?
- Can it answer its own questions? If it calls five other services for every request, the line is wrong.
Notifications fail the first test with tickets: they change for different reasons, on a different schedule. That is exactly why they can stand apart.
The warning signs show up afterwards. The ticket page calls tickets, people, comments, tags, notifications and the AI service: six calls for one screen, so it is chatty. Changes always ship together. Tables are shared. If two services always change together, they are really one service.
Every table has one owner
The tickets service owns the tickets table. The stats service wants that data, and it could reach straight into the table. That is the one thing you do not allow. It asks through the tickets API instead. Only the owner writes the table; everyone else asks through its door.
Why so strict? Say three services share one table and the tickets team renames a column, status to state. A small, sensible clean-up, and stats and the AI service break, because nobody knew they were reading it. A shared table is a contract nobody wrote down.
When two services want the same data
| Option | Freshness | Independence | Price | Use it for |
|---|---|---|---|---|
| Shared table | Always fresh | None | Hidden coupling | Avoid between services |
| Ask the owner | Always fresh | Needs the owner up | A network call every time | Answers that must be exact |
| Keep a copy | A little behind | High | Events to keep it current | Reports, lists, search |
| Merge them | Always fresh | One service again | A bigger service | Parts that always change together |
A copy done right: Emma resolves ticket 8814, tickets announces a TicketResolved event, and stats moves its "resolved today" counter from 41 to 42. Stats kept only the ticket id, the status and the time, not the whole ticket. The copy is read-only and small, and if it goes wrong you rebuild it from the owner. Publishing those events safely is covered in events and the transactional outbox.
Before you draw the line
- What does this service own, in one sentence?
- Which tables are its own, and is it the only writer?
- For each need from another service: ask, copy or merge?
- When the other service is down, what does the user see?
- Can one change stay inside one service?
Applied: what leaves Relay
In the first capstone, Relay is one jar, relay-api, with 59 classes. Around it sit PostgreSQL (tickets, comments, SLA deadlines), a Kafka topic ticket-events, and Redis remembering which emails were sent. Three packages look like they could live on their own: notifications, search and the SLA ladder (the rules that decide when a ticket is due). Each is checked with four questions:
- Does it change on its own?
- Does it need only a contract from the rest of the system?
- Is it outside every ticket write (not in the same transaction as the ticket)?
- Is there a pain you can name and measure?
A small Java tool reads Relay's source and answers the first three. The fourth is a judgement.
| Notifications | Search | SLA ladder | |
|---|---|---|---|
| Changes on its own | 0 files outside use it | 1 file calls it | Found in 12 files |
| Needs only a contract | One event (TicketEvent, Status, the topic name) | The ticket text | The whole ticket |
| Outside ticket writes | None | None | Create and update |
| A pain you can name | Bursts, mail outages | Slow LIKE scans, exact words only | Nothing |
| Decision | Leaves | Leaves | Stays |
The SLA ladder is the instructive one. When the priority changes, the deadline moves in the same transaction. Split it out and a ticket could be saved with a new priority and an old deadline. Leaving it in the monolith on purpose is a decision too. Two services leave, and the core keeps its tickets and its transaction. The extraction itself is in extracting the notifications service.
StudyEasy AI Community
Learn AI engineering, share what you build, and connect with other learners.
Free resources: lesson files, notebooks and code
Ask questions and join engineering discussions
Meet real people learning and building with AI
Related course on Udemy
FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE
Java 25, JSP, Hibernate, Spring Boot 4, REST APIs, React and Spring AI.View on Udemy ↗: FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE (paid course, opens in a new tab)Related posts
Fallback Models for an LLM App: A Chain That Checks Region and Fit, Flags Degraded Answers and Gets Rehearsed
When the main model goes down, the backup has to be allowed to take the data, able to read the whole request and tested before the bad day. A simulated four-model chain for an EU customer: a 6,000-token request lands on mid-eu, flagged degraded; a 10,000-token request is served by nobody, on purpose.
Back Pressure for LLM Traffic: Bound the Queue, Give Chat Its Own Lane, Count Tokens, Cancel When the Caller Leaves
A bulk upload buries the chat. In a small simulation, one shared queue grows to 199 waiting and the middle chat answer takes 80.2 s. A bound plus a chat lane brings it to 0.35 s while 178 bulk jobs are told to retry in 10 s, and cancelling abandoned calls saves 21,000 wasted tokens.
Load Balancing LLM Traffic: Count the Work, Weigh the Prefix Cache, Check Real Health, Drain Before Deploys
Six GPU replicas, two at 95% and four at 30%: round robin counts requests, and requests aren't equal. In a small simulation, least outstanding requests cuts p95 from 6.52 s to 3.05 s, prefix affinity lifts cache hits to 95% but pushes p95 to 11.45 s, a real health check takes errors from 48 to 2, and draining cuts 0 answers instead of 4.
A Message Queue for Document Ingestion: At Least Once, Leases, an Idempotent Consumer and a Dead Letter Queue
A queue doesn't lose a document, but it can hand one out twice. In a small simulation, a worker crash makes document two go from 3 to 6 chunks and the index holds 11 when the documents hold 8. An idempotent consumer brings it back to 8 with the same two deliveries, and a limit of three tries moves a poison file to a dead letter queue.
