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

- Speaker: 
- Event: [Reversim Summit 2020](/wiki/years/2020.md)
- Video: https://www.youtube.com/watch?v=NmvK4pHUuaw
- Transcript: [/transcripts/2020/17-NmvK4pHUuaw.md](/transcripts/2020/17-NmvK4pHUuaw.md)
- Language: Hebrew and English · Type: talk · Level: intermediate
- Topics: [Performance](/wiki/topics/performance.md), [Data Science](/wiki/topics/data-science.md), [Databases](/wiki/topics/databases.md), [Distributed Systems](/wiki/topics/distributed-systems.md)

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

## Summary

This talk explores architectural patterns and trade-offs for sharing data between microservices using in-memory data grids. The speaker discusses how to balance the need for fast data access and high performance against the coupling introduced by shared state. Through a Q&A session, the audience learns about out-of-heap memory management, serialization overhead, and alternatives like message queues and actor models.

## Key points

- [0:00](https://www.youtube.com/watch?v=NmvK4pHUuaw) The speaker explains that off-heap memory resides in the JVM's memory space but is managed outside of the garbage collection mechanism.
- [1:02](https://www.youtube.com/watch?v=NmvK4pHUuaw&t=62s) Managing memory off-heap avoids garbage collection pauses, but it introduces overhead due to serialization and deserialization.
- [2:05](https://www.youtube.com/watch?v=NmvK4pHUuaw&t=125s) Sharing data structures across microservices creates tight coupling, trading traditional database independence for performance gains.
- [3:12](https://www.youtube.com/watch?v=NmvK4pHUuaw&t=192s) Services share Java libraries and maintain backward compatibility to handle data structures, similar to how they manage other dependencies.
- [4:12](https://www.youtube.com/watch?v=NmvK4pHUuaw&t=252s) Data can be ingested into the in-memory grid either by querying the source system directly via REST or RPC, or by consuming from a message broker.
- [6:31](https://www.youtube.com/watch?v=NmvK4pHUuaw&t=391s) Actor models like Akka provide concurrency without locks, but they are not designed to serve as in-memory data grids or general-purpose databases.
- [8:36](https://www.youtube.com/watch?v=NmvK4pHUuaw&t=516s) Entity version upgrades require shared client libraries that are capable of supporting multiple previous versions across microservices.
- [11:39](https://www.youtube.com/watch?v=NmvK4pHUuaw&t=699s) Distributed data grids synchronize data across separate JVM instances running in different containers using built-in discovery mechanisms.

## Takeaways

- Evaluate whether performance requirements justify the tight coupling of sharing data structures between microservices.
- Understand the trade-offs of using off-heap memory to avoid garbage collection overhead at the cost of serialization complexity.
- Use shared client libraries and backward compatibility strategies when evolving data schemas across distributed services.

## Questions this talk answers

- How does using an in-memory data grid compare to traditional messaging queues or caches like Redis for microservices?
- What are the garbage collection and serialization trade-offs of storing state off-heap in a JVM environment?
- How do you handle schema evolution and version upgrades for shared data structures across multiple independent services?

## Technologies

Java, JVM, Kafka, Redis, Akka, Cassandra, Docker, Hazelcast

## Tags

data sharing, distributed systems, jvm, memory management, microservices, performance
