Skip to content

Sharing Data

The Importance of Data Ownership and Coupling

Section titled “The Importance of Data Ownership and Coupling”
  • The core challenge in microservices is services needing to interact, often involving data that each service owns.
  • Excessive data sharing and direct data access between services lead to tight coupling.
  • A guiding principle is that each microservice should own its data without granting direct external access to it.
  • Tight coupling from direct data access undermines system flexibility and independence.
  • Information hiding involves concealing as much data as possible behind a service’s boundaries.
  • Not exposing a service’s internal data schema to outside consumers gives teams the freedom to modify implementation without breaking dependencies.
  • Introducing a layer (such as Data Transfer Objects, DTOs) between storage and API allows internal schema changes while maintaining a consistent external contract.
  • Changing internal details like database field names becomes low-risk, as only the mapping to DTOs needs updating.
  • DTOs are simple objects used to define exactly what data is exposed externally, different from business logic models or entities.
  • By mapping business/domain objects to DTOs, teams decouple internal schema from external API contracts.
  • APIs in this context include REST endpoints as well as schemas for message buses; the principle applies beyond just web APIs.
  • A useful heuristic: design internal APIs as if they were public, consumer-facing services visible to external users.
  • This mindset discourages leaking internal details or making assumptions about who is consuming the service.
  • Information hiding between microservices is critical for reducing coupling and promoting independent, flexible development.