Skip to content

ADR-001: One shared MongoDB database

Status: Accepted (origin not recorded; documented 2026-11-06)

Context

Glacez started as a single application and was split into Spring Boot services over time. Each service needed persistence, and the split happened inside an existing MongoDB deployment. Every service now declares spring.data.mongodb.database: ${DATABASE_NAME}, and the charts render that value from database/main_db — the same glacez database everywhere.

The alternative — a database per service — would have required splitting collections, rewriting queries and introducing cross-service APIs for data the calculation services need on every request. That work was never scheduled.

Decision

One database, one namespace, ownership by convention.

  • A service may write only the document types its domain produces.
  • A service may read another domain's documents through its own repository when it needs the data (portfolio reads credential and wallet, simulator reads strategy and action, core reads wallet).
  • Cross-service logic goes through Feign; cross-service data does not.

Alternatives considered

  • Database per service. True isolation, real boundaries, and an honest failure mode. Rejected on cost: it needs a data migration, a query API for every cross-domain read, and a distributed transaction story for the trading path.
  • Collection prefixes per service in the shared database. Cheaper than separate databases but buys nothing: the shared connection still grants everything, and the prefix would have to be threaded through every model.
  • Read replicas per service. Adds operational surface without changing the write topology.

Consequences

  • Isolation is a review property, not an infrastructure property. Nothing prevents a wrong write; a person or a test does.
  • Cross-domain reads are cheap and fast (a repository call, no network hop), which is why the calculation services depend on it.
  • A future split is a project, not a refactor: it needs a migration plan per document type, back-compatible dual reads, and a sequencing story for the trading path.
  • The "no cross-service database access" rule in Glacez/AGENTS.md therefore means no writes outside your domain. Read Data ownership for the working table.