Wiki: Keep your Logic Close and Your Data Closer - How to Share data Between Services

For agents: Markdown version · Wiki index · Explore

Written by an LLM from machine transcripts. It can contain errors. Check the transcript before you quote it.

Summary

This talk explores the architectural tension between microservices, which aim for encapsulation and hiding implementation details, and databases, which are designed to expose data. The speaker analyzes common anti-patterns like bloating APIs with complex filters or treating the database itself as a shared interface. To solve the challenge of sharing data efficiently between services without violating encapsulation, the speaker proposes using an in-memory data grid. The audience learns how data grids allow multiple services to share state directly via JVM memory while maintaining flexibility, reliability, and testability.

Key points

  • 1:21 Microservices are built around encapsulation and hiding implementation details, whereas databases are explicitly designed to expose and share data, creating an inherent conflict.
  • 3:25 A naive microservice API design often starts simple with basic CRUD operations, but quickly grows complex as consumers demand advanced filtering and raw data.
  • 11:05 Using a database directly as an integration interface is problematic because databases are physical, stateful singletons that lack modern software testing and gradual rollout capabilities.
  • 14:52 An event-driven architecture using Kafka can solve cross-domain data sharing by streaming changes, but it requires significant infrastructure tuning and acts as a single point of failure.
  • 18:08 Drawing inspiration from how threads share memory within a JVM, an ideal solution would allow different JVMs across services to share state directly.
  • 21:40 An in-memory data grid enables multiple services to share data structures across JVMs while keeping the database hidden and avoiding heavy network overhead.
  • 33:53 By treating the data grid as a cache rather than the single source of truth, systems can easily recover from failures by falling back to the primary domain service.
  • 38:09 While in-memory data grids solve cross-service data sharing, they introduce new dependencies such as shared data types and are restricted to JVM-based languages.

Takeaways

  • Avoid exposing complex query parameters or raw database access through microservice APIs.
  • Treat distributed caches and data grids as caches rather than the primary source of truth to ensure system resilience.
  • Leverage in-memory data grids to share domain state across JVMs without heavy network calls or database coupling.

Questions this talk answers

  • How can I share large amounts of data between microservices without coupling them directly to a database?
  • What are the architectural trade-offs between using Kafka and an in-memory data grid for cross-service data synchronization?
  • How do in-memory data grids handle garbage collection and memory management when storing millions of entities?

Technologies

Java, Kafka, Apache Ignite, Node.js, Kotlin, Cassandra, MySQL, GraphQL, gRPC, REST

Tags

architecture, caching, data sharing, distributed systems, microservices