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

- Speaker: [Yonatan Maman](/wiki/speakers/yonatan-maman.md)
- Event: [Reversim Summit 2020](/wiki/years/2020.md)
- Video: https://www.youtube.com/watch?v=GB1IXhqEn70
- Transcript: [/transcripts/2020/05-GB1IXhqEn70.md](/transcripts/2020/05-GB1IXhqEn70.md)
- Language: Hebrew · Type: talk · Level: intermediate
- Topics: [Architecture](/wiki/topics/architecture.md), [Scalability](/wiki/topics/scalability.md), [Data Science](/wiki/topics/data-science.md), [Databases](/wiki/topics/databases.md)

> 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](https://www.youtube.com/watch?v=GB1IXhqEn70&t=81s) 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](https://www.youtube.com/watch?v=GB1IXhqEn70&t=205s) 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](https://www.youtube.com/watch?v=GB1IXhqEn70&t=665s) 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](https://www.youtube.com/watch?v=GB1IXhqEn70&t=892s) 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](https://www.youtube.com/watch?v=GB1IXhqEn70&t=1088s) 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](https://www.youtube.com/watch?v=GB1IXhqEn70&t=1300s) 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](https://www.youtube.com/watch?v=GB1IXhqEn70&t=2033s) 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](https://www.youtube.com/watch?v=GB1IXhqEn70&t=2289s) 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
