SlideShare a Scribd company logo
Architectural Caching Patterns
for Kubernetes
Rafał Leszko
@RafalLeszko
rafalleszko.com
Hazelcast
About me
● Cloud Software Engineer at Hazelcast
● Worked at Google and CERN
● Author of the book "Continuous Delivery
with Docker and Jenkins"
● Trainer and conference speaker
● Live in Kraków, Poland
About Hazelcast
● Distributed Company
● Open Source Software
● 140+ Employees
● Products:
○ Hazelcast IMDG
○ Hazelcast Jet
○ Hazelcast Cloud
@Hazelcast
www.hazelcast.com
● Introduction
● Caching Architectural Patterns
○ Embedded
○ Embedded Distributed
○ Client-Server
○ Cloud
○ Sidecar
○ Reverse Proxy
○ Reverse Proxy Sidecar
● Summary
Agenda
Service 1
Service 2
v1
Service 2
v2
Service 1
Service 4
v1
Service 4
v2
Service 4
v3
Ruby
Microservice World
Microservice World
Service 1
Service 2
v1
Service 2
v2
Service 1
Service 4
v1
Service 4
v2
Service 4
v3
Ruby
cache
cache
cache
cache
Microservice World
Service 1
Service 2
v1
Service 2
v2
Service 1
Service 4
v1
Service 4
v2
Service 4
v3
Ruby
cache
cache
cache
Microservice World
Service 1
Service 2
v1
Service 2
v2
Service 1
Service 4
v1
Service 4
v2
Service 4
v3
Ruby
cache
cache
cache
● Introduction ✔
● Caching Architectural Patterns
○ Embedded
○ Embedded Distributed
○ Client-Server
○ Cloud
○ Sidecar
○ Reverse Proxy
○ Reverse Proxy Sidecar
● Summary
Agenda
1. Embedded
Application
Kubernetes
Service
Cache
Application
Cache
Request
Embedded Cache
Kubernetes Pod
Kubernetes Pod
private ConcurrentHashMap<String, String> cache =
new ConcurrentHashMap<>();
private String processRequest(String request) {
if (cache.contains(request)) {
return cache.get(request);
}
String response = process(request);
cache.put(request, response);
return response;
}
Embedded Cache (Pure Java implementation)
private ConcurrentHashMap<String, String> cache =
new ConcurrentHashMap<>();
private String processRequest(String request) {
if (cache.contains(request)) {
return cache.get(request);
}
String response = process(request);
cache.put(request, response);
return response;
}
Embedded Cache (Pure Java implementation)
● No Eviction Policies
● No Max Size Limit
(OutOfMemoryError)
● No Statistics
● No built-in Cache Loaders
● No Expiration Time
● No Notification Mechanism
Java Collection is not a Cache!
CacheBuilder.newBuilder()
.initialCapacity(300)
.expireAfterAccess(Duration.ofMinutes(10))
.maximumSize(1000)
.build();
Embedded Cache (Java libraries)
Embedded Cache (Java libraries)
CacheBuilder.newBuilder()
.initialCapacity(300)
.expireAfterAccess(Duration.ofMinutes(10))
.maximumSize(1000)
.build();
Caching Application Layer
@Service
public class BookService {
@Cacheable("books")
public String getBookNameByIsbn(String isbn) {
return findBookInSlowSource(isbn);
}
}
Caching Application Layer
@Service
public class BookService {
@Cacheable("books")
public String getBookNameByIsbn(String isbn) {
return findBookInSlowSource(isbn);
}
}
Be Careful, Spring uses ConcurrentHashMap by default!
Embedded Cache
Application
Kubernetes
Service
Cache
Application
Cache
Request
Kubernetes Pod
Kubernetes Pod
1*. Embedded Distributed
Application
Application
Kubernetes
Service
Cache
Cache
Request
Hazelcast
Cluster
Embedded Distributed Cache
Kubernetes Pod
Kubernetes Pod
@Configuration
public class HazelcastConfiguration {
@Bean
CacheManager cacheManager() {
return new HazelcastCacheManager(
Hazelcast.newHazelcastInstance());
}
}
Embedded Distributed Cache (Spring with Hazelcast)
Hazelcast Discovery Plugins
Hazelcast Discovery Plugins
Embedded Distributed Cache
Application
Application
Kubernetes
Service
Cache
Cache
Request
Hazelcast
Cluster
Kubernetes Pod
Kubernetes Pod
Embedded Cache
Pros Cons
● Simple configuration /
deployment
● Low-latency data access
● No separate Ops Team
needed
● Not flexible management
(scaling, backup)
● Limited to JVM-based
applications
● Data collocated with
applications
● Introduction ✔
● Caching Architectural Patterns
○ Embedded ✔
○ Embedded Distributed ✔
○ Client-Server
○ Cloud
○ Sidecar
○ Reverse Proxy
○ Reverse Proxy Sidecar
● Summary
Agenda
2. Client-Server
Application
Kubernetes
Service
Application
Request
Cache Server
StatefulSet
Client-Server Cache
Kubernetes Pod
Kubernetes Pod
Client-Server Cache
Application
Kubernetes
Service
Application
Request
Cache Server
StatefulSet
Kubernetes Pod
Kubernetes Pod
Client-Server Cache
Separate Management:
● backups
● (auto) scaling
● security
Ops Team
Application
Kubernetes
Service
Application
Request
Cache Server
StatefulSet
Kubernetes Pod
Kubernetes Pod
Client-Server Cache
Application
Kubernetes
Service
Application
Request
Cache Server
StatefulSet
Kubernetes Pod
Kubernetes Pod
Client-Server Cache
Application
Kubernetes
Service
Application
Request
Cache Server
StatefulSet
Kubernetes Pod
Kubernetes Pod
Client-Server Cache
Client-Server Cache
Client-Server Cache
Starting Hazelcast Cache Server
$ helm install hazelcast/hazelcast
Client-Server Cache
Hazelcast Client
@Configuration
public class HazelcastClientConfiguration {
@Bean
CacheManager cacheManager() {
ClientConfig clientConfig = new ClientConfig();
clientConfig.getNetworkConfig().getKubernetesConfig()
.setEnabled(true);
return new HazelcastCacheManager(HazelcastClient
.newHazelcastClient(clientConfig));
}
}
Starting Hazelcast Cache Server
$ helm install hazelcast/hazelcast
Client-Server Cache
Separate Management:
● backups
● (auto) scaling
● security
Ops Team
Application
Kubernetes
Service
Application
Request
Cache Server
StatefulSet
Kubernetes Pod
Kubernetes Pod
2*. Cloud
Application
Kubernetes
Service
Application
Request
Cloud (Cache as a Service)
Kubernetes Pod
Kubernetes Pod
Cloud (Cache as a Service)
Management:
● backups
● (auto) scaling
● security
Ops Team
Application
Kubernetes
Service
Application
Request
Kubernetes Pod
Kubernetes Pod
Cloud (Cache as a Service)
Management:
● backups
● (auto) scaling
● security
Ops Team
Application
Kubernetes
Service
Application
Request
Kubernetes Pod
Kubernetes Pod
Cloud (Cache as a Service)
Application
Kubernetes
Service
Application
Request
Kubernetes Pod
Kubernetes Pod
@Configuration
public class HazelcastCloudConfiguration {
@Bean
CacheManager cacheManager() {
ClientConfig clientConfig = new ClientConfig();
clientConfig.getNetworkConfig().getCloudConfig()
.setEnabled(true)
.setDiscoveryToken("KSXFDTi5HXPJGR0wRAjLgKe45tvEEhd");
clientConfig.setGroupConfig(
new GroupConfig("test-cluster", "b2f984b5dd3314"));
return new HazelcastCacheManager(
HazelcastClient.newHazelcastClient(clientConfig));
}
}
Cloud (Cache as a Service)
Client-Server (Cloud) Cache
Pros
● Data separate from
applications
● Separate management
(scaling, backup)
● Programming-language
agnostic
Cons
● Separate Ops effort
● Higher latency
● Server network requires
adjustment (same region,
same VPC)
● Introduction ✔
● Caching Architectural Patterns
○ Embedded ✔
○ Embedded Distributed ✔
○ Client-Server ✔
○ Cloud ✔
○ Sidecar
○ Reverse Proxy
○ Reverse Proxy Sidecar
● Summary
Agenda
3. Sidecar
Kubernetes Service
Request
Hazelcast
Cluster
Kubernetes POD
Application Container
Cache Container
Application Container
Cache Container
Kubernetes POD
Sidecar Cache
Sidecar Cache
Similar to Embedded:
● the same physical machine
● the same resource pool
● scales up and down together
● no discovery needed (always localhost)
Similar to Client-Server:
● different programming language
● uses cache client to connect
● clear isolation between app and cache
@Configuration
public class HazelcastSidecarConfiguration {
@Bean
CacheManager cacheManager() {
ClientConfig clientConfig = new ClientConfig();
clientConfig.getNetworkConfig()
.addAddress("localhost:5701");
return new HazelcastCacheManager(HazelcastClient
.newHazelcastClient(clientConfig));
}
}
Sidecar Cache
Sidecar Cache
apiVersion: apps/v1
kind: Deployment
...
spec:
template:
spec:
containers:
- name: application
image: leszko/application
- name: hazelcast
image: hazelcast/hazelcast
Sidecar Cache
Pros Cons
● Simple configuration
● Programming-language
agnostic
● Low latency
● Some isolation of data and
applications
● Not flexible management
(scaling, backup)
● Data collocated with
application PODs
● Introduction ✔
● Caching Architectural Patterns
○ Embedded ✔
○ Embedded Distributed ✔
○ Client-Server ✔
○ Cloud ✔
○ Sidecar ✔
○ Reverse Proxy
○ Reverse Proxy Sidecar
● Summary
Agenda
4. Reverse Proxy
Application
Kubernetes
Service
Cache
Application
Request
Reverse Proxy Cache
Kubernetes Pod
Kubernetes Pod
Reverse Proxy Cache
http {
...
proxy_cache_path /data/nginx/cache
keys_zone=one:10m;
...
}
● Only for HTTP
● Not distributed
● No High Availability
● Data stored on the disk
NGINX Reverse Proxy Cache Issues
4*. Reverse Proxy Sidecar
Kubernetes Service
Request
Hazelcast
Cluster
Kubernetes POD
Application Container
Reverse Proxy Cache
Container
Application Container
Reverse Proxy Cache
Container
Kubernetes POD
Reverse Proxy Sidecar Cache
Architectural caching patterns for kubernetes
Good
Reverse Proxy Sidecar Cache
Service 1
Service 2
v1
Service 2
v2
Service 1
Service 4
v1
Service 4
v2
Service 4
v3
Ruby
Reverse Proxy Sidecar Cache
Service 1
Service 2
v1
Service 2
v2
Service 1
Service 4
v1
Service 4
v2
Service 4
v3
Ruby
Bad
Architectural caching patterns for kubernetes
Reverse Proxy Cache
@CacheEvict(value = "someValue", allEntries = true)
public void evictAllCacheValues() {}
Application Cache:
Reverse Proxy Cache
@CacheEvict(value = "someValue", allEntries = true)
public void evictAllCacheValues() {}
Application Cache:
Proxy Cache:
http {
...
location / {
add_header Cache-Control public;
expires 86400;
etag on;
}
}
Reverse Proxy (Sidecar) Cache
Pros Cons
● Configuration-based (no
need to change
applications)
● Programming-language
agnostic
● Consistent with containers
and microservice world
● Difficult cache invalidation
● No mature solutions yet
● Protocol-based (e.g. works
only with HTTP)
● Introduction ✔
● Caching Architectural Patterns
○ Embedded ✔
○ Embedded Distributed ✔
○ Client-Server ✔
○ Cloud ✔
○ Sidecar ✔
○ Reverse Proxy ✔
○ Reverse Proxy Sidecar ✔
● Summary
Agenda
Summary
application-aware?
application-aware?
early adopter?
no
application-aware?
Reverse Proxy
no
no
early adopter?
application-aware?
Reverse Proxy
Reverse Proxy
Sidecar
no
yes no
early adopter?
application-aware?
Reverse Proxy
Reverse Proxy
Sidecar
lot of data?
security restrictions?
yes no
yes no
early adopter?
application-aware?
Reverse Proxy
Reverse Proxy
Sidecar
lot of data?
security restrictions?
language-agnostic?
yes no
yes nono
early adopter?
application-aware?
Reverse Proxy
Reverse Proxy
Sidecar
lot of data?
security restrictions?
language-agnostic?
Embedded
(Distributed)
yes no
yes no
no
no
early adopter?
application-aware?
Reverse Proxy
Reverse Proxy
Sidecar
lot of data?
security restrictions?
language-agnostic?
Embedded
(Distributed)
Sidecar
yes no
yes
yes no
no
no
early adopter?
application-aware?
Reverse Proxy
Reverse Proxy
Sidecar
lot of data?
security restrictions?
language-agnostic?
Embedded
(Distributed)
Sidecar
cloud?
yes no
yes
yes
yes no
no
no
early adopter?
application-aware?
Reverse Proxy
Reverse Proxy
Sidecar
lot of data?
security restrictions?
language-agnostic?
Embedded
(Distributed)
Sidecar
cloud?
Client-Server
yes no
yes
yes
yes no
nono
no
early adopter?
application-aware?
Reverse Proxy
Reverse Proxy
Sidecar
lot of data?
security restrictions?
language-agnostic?
Embedded
(Distributed)
Sidecar
cloud?
Client-ServerCloud
yes no
yes
yes yes
yes no
nono
no
early adopter?
Resources
● Hazelcast Sidecar Container Pattern:
https://hazelcast.com/blog/hazelcast-sidecar-container-pattern/
● Hazelcast Reverse Proxy Sidecar Caching Prototype:
https://github.com/leszko/caching-injector
● Caching Best Practices:
https://vladmihalcea.com/caching-best-practices/
● NGINX HTTP Reverse Proxy Caching:
https://www.nginx.com/resources/videos/best-practices-for-caching/
Thank You!
Rafał Leszko
@RafalLeszko

More Related Content

PPTX
ppt on reading skills by harshid panchal
ODP
Lisa 2015-gluster fs-hands-on
PDF
Architectural caching patterns for kubernetes
PDF
Architectural patterns for caching microservices
PDF
[jLove 2020] Where is my cache architectural patterns for caching microservi...
PDF
Where is my cache? Architectural patterns for caching microservices by example
PDF
Where is my cache architectural patterns for caching microservices by example
PDF
Where is my cache architectural patterns for caching microservices by example
ppt on reading skills by harshid panchal
Lisa 2015-gluster fs-hands-on
Architectural caching patterns for kubernetes
Architectural patterns for caching microservices
[jLove 2020] Where is my cache architectural patterns for caching microservi...
Where is my cache? Architectural patterns for caching microservices by example
Where is my cache architectural patterns for caching microservices by example
Where is my cache architectural patterns for caching microservices by example

Similar to Architectural caching patterns for kubernetes (20)

PDF
Where is my cache? Architectural patterns for caching microservices by example
PDF
Where is my cache? Architectural patterns for caching microservices by example
PDF
[DevopsDays India 2019] Where is my cache? Architectural patterns for caching...
PDF
Where is my cache architectural patterns for caching microservices by example
PDF
Architectural patterns for high performance microservices in kubernetes
PDF
Second Skin: Real-Time Retheming a Legacy Web Application with Diazo in the C...
PDF
stackconf 2020 | The path to a Serverless-native era with Kubernetes by Paolo...
PPTX
GCP - Continuous Integration and Delivery into Kubernetes with GitHub, Travis...
PDF
Making Service Deployments to AWS a breeze with Nova
PDF
Red Hat Container Development Kit
PDF
Deep dive into OpenStack storage, Sean Cohen, Red Hat
PDF
Deep Dive into Openstack Storage, Sean Cohen, Red Hat
PDF
LINE's Private Cloud - Meet Cloud Native World
PPTX
High Performance Cloud-Native Microservices With Distributed Caching
PDF
The path to a serverless-native era with Kubernetes
PPTX
Best practices for developing your Magento Commerce on Cloud
PDF
Como creamos QuestDB Cloud, un SaaS basado en Kubernetes alrededor de QuestDB...
PPTX
Pivotal cloud cache for .net microservices
PDF
CON6423: Scalable JavaScript applications with Project Nashorn
PPTX
Container orchestration and microservices world
Where is my cache? Architectural patterns for caching microservices by example
Where is my cache? Architectural patterns for caching microservices by example
[DevopsDays India 2019] Where is my cache? Architectural patterns for caching...
Where is my cache architectural patterns for caching microservices by example
Architectural patterns for high performance microservices in kubernetes
Second Skin: Real-Time Retheming a Legacy Web Application with Diazo in the C...
stackconf 2020 | The path to a Serverless-native era with Kubernetes by Paolo...
GCP - Continuous Integration and Delivery into Kubernetes with GitHub, Travis...
Making Service Deployments to AWS a breeze with Nova
Red Hat Container Development Kit
Deep dive into OpenStack storage, Sean Cohen, Red Hat
Deep Dive into Openstack Storage, Sean Cohen, Red Hat
LINE's Private Cloud - Meet Cloud Native World
High Performance Cloud-Native Microservices With Distributed Caching
The path to a serverless-native era with Kubernetes
Best practices for developing your Magento Commerce on Cloud
Como creamos QuestDB Cloud, un SaaS basado en Kubernetes alrededor de QuestDB...
Pivotal cloud cache for .net microservices
CON6423: Scalable JavaScript applications with Project Nashorn
Container orchestration and microservices world
Ad

More from Rafał Leszko (15)

PDF
Build Your Kubernetes Operator with the Right Tool!
PDF
Mutation Testing with PIT
PDF
Distributed Locking in Kubernetes
PDF
Mutation testing with PIT
PDF
Build your operator with the right tool
PDF
5 levels of high availability from multi instance to hybrid cloud
PDF
5 Levels of High Availability: From Multi-instance to Hybrid Cloud
PDF
Stream Processing in the Cloud - Athens Kubernetes Meetup 16.07.2019
PDF
Stream Processing with Hazelcast Jet - Voxxed Days Thessaloniki 19.11.2018
PDF
Mutation Testing - Voxxed Days Cluj-Napoca 2017
PDF
Continuous Delivery - Voxxed Days Cluj-Napoca 2017
PDF
Continuous Delivery - Voxxed Days Bucharest 2017
PDF
Mutation Testing - Voxxed Days Bucharest 10.03.2017
PDF
Continuous Delivery - Devoxx Morocco 2016
PDF
Continuous Delivery - Voxxed Days Thessaloniki 21.10.2016
Build Your Kubernetes Operator with the Right Tool!
Mutation Testing with PIT
Distributed Locking in Kubernetes
Mutation testing with PIT
Build your operator with the right tool
5 levels of high availability from multi instance to hybrid cloud
5 Levels of High Availability: From Multi-instance to Hybrid Cloud
Stream Processing in the Cloud - Athens Kubernetes Meetup 16.07.2019
Stream Processing with Hazelcast Jet - Voxxed Days Thessaloniki 19.11.2018
Mutation Testing - Voxxed Days Cluj-Napoca 2017
Continuous Delivery - Voxxed Days Cluj-Napoca 2017
Continuous Delivery - Voxxed Days Bucharest 2017
Mutation Testing - Voxxed Days Bucharest 10.03.2017
Continuous Delivery - Devoxx Morocco 2016
Continuous Delivery - Voxxed Days Thessaloniki 21.10.2016
Ad

Recently uploaded (20)

PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
System and Network Administraation Chapter 3
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPT
Introduction Database Management System for Course Database
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Nekopoi APK 2025 free lastest update
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
System and Network Administration Chapter 2
PDF
Digital Strategies for Manufacturing Companies
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Operating system designcfffgfgggggggvggggggggg
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
System and Network Administraation Chapter 3
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Introduction Database Management System for Course Database
How Creative Agencies Leverage Project Management Software.pdf
PTS Company Brochure 2025 (1).pdf.......
Navsoft: AI-Powered Business Solutions & Custom Software Development
Nekopoi APK 2025 free lastest update
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
System and Network Administration Chapter 2
Digital Strategies for Manufacturing Companies
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Wondershare Filmora 15 Crack With Activation Key [2025
Upgrade and Innovation Strategies for SAP ERP Customers
VVF-Customer-Presentation2025-Ver1.9.pptx

Architectural caching patterns for kubernetes