Data Ownership
The fact that shapes everything
Every SOA points at one shared MongoDB database. Each impl/src/main/resources/application.yaml declares:
spring:
data:
mongodb:
database: ${DATABASE_NAME}
and the charts render DATABASE_NAME from the database/main_db secret — glacez in every environment. There is no per-service database, no per-service schema, no collection prefix.
So "a service owns its data" is an ownership convention enforced by code review, not an isolation property of the infrastructure. Consequences to internalise:
- Any service can physically read or write any collection. Nothing stops it but its own repositories.
- A wrong write is not caught by a boundary; it is caught by a person, a test, or a corrupted report three days later.
- "No cross-service database access" (a rule in
Glacez/AGENTS.md) means no writes outside your domain, not no reads.
What is actually practised
Two different disciplines, both real:
- Writes are grouped by domain. A service writes the document types its domain produces. Three services are legitimate co-writers because they hold three different stages of a document's life:
webservicefor user-initiated changes (it is the API surface),corefor synchronization and tracking,workerfor state observed from exchanges. - Reads often go straight to the collection.
portfolioreadsCredentialandWalletthrough its own repositories;simulatorreadsStrategyandActionthe same way;corereadsWallet. This is deliberate and cheap — the alternative (a Feign call per lookup) would add a network hop and a version to every calculation.
Feign is for computation and side effects, not for simple lookups. Keep it that way: a new read that only needs the stored document should use a repository; a read that needs another service's logic (pricing, coherence, execution) must use its API.
Ownership table
Derived on 2026-11-06 from repository usage in each service (save/insert/delete calls for the primary writer; find/count/exists for direct readers). Method-specific repository names (closedOrderRepository, depositRepository, withdrawalRepository) all persist the same document types listed here.
| Domain | Document types | Primary writer(s) | Direct readers |
|---|---|---|---|
| Identity | GlacezUser, Credential, ExternalApiKey, ExchangeInfo, InvestmentProfile, Note |
core (credential + user lifecycle), worker (credential + exchange state), agent (investment profile), findata (API keys), webservice (user-facing edits) |
portfolio (credential), webservice (all) |
| Strategies | Strategy, Action, StrategyTrack, ActionTrack |
core |
simulator, webservice |
| Portfolio & trading | Order, Transfer, Wallet, TransactionTrack |
core (sync, tracking), portfolio (recomputation), worker (execution results), webservice (user actions) |
portfolio (wallet), core (wallet), simulator (simulation order shapes) |
| Exchange records | RecordOrder, RecordTransfer, RecordSpot, RecordEarn, RecordFile |
worker (import), webservice (user-visible CRUD) |
– |
| Events | Event |
core, worker, webservice |
all |
| Market data | Currency, Ohlcv, MarketMetrics, HalvingEvent, FearAndGreed, News |
findata |
simulator, webservice |
| Simulations | Simulation, SimulationSnapshot, SimulationTransaction |
simulator |
webservice |
| AI reports | DailyPortfolioReport, DailyPositionsReport, AgentBtcTrendReport, AgentNewsReport, AgentProfile |
agent |
webservice |
Collection names follow the Spring Data default (decapitalised class name) except where a model overrides it — News maps to news_articles.
To re-derive any row: grep -rhoE "\b[a-z][A-Za-z]*Repository\.(save|saveAll|insert|delete)[A-Za-z]*\(" --include=*.java <repo> in the service you suspect.
Rules for new code
- Write only what your service's domain produces. If a feature needs a document written by another service, that service grows an endpoint — do not add the repository.
- Reads: repository for data, Feign for logic. Same rule as above, in the other direction.
- A new document type belongs to one writer. If two services must create it, the lifecycle differs and the document should be split or given an explicit owner per stage.
- No schema migrations exist. There is no Flyway/Liquibase and
glacez-infra-databaseonly bootstraps. A shape change ships as a script plus a plan in the MR description, with back-compatible reads. - A test that writes to a collection another service owns is a red flag in review, not a shortcut.
Why it is like this
Shared database was a deliberate, dated decision with real consequences for how the platform evolves. Read ADR-001 before proposing per-service databases or a data-splitting refactor.