95
Where is my cache? Architectural patterns for caching microservices by example Rafał Leszko @RafalLeszko rafalleszko.com Hazelcast

Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

  • Upload
    others

  • View
    13

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Where is my cache?Architectural patterns for caching

microservices by example

Rafał Leszko @RafalLeszkorafalleszko.com

Hazelcast

Page 2: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

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

Page 3: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

About Hazelcast● Distributed Company● Open Source Software● 140+ Employees● Products:

○ Hazelcast IMDG○ Hazelcast Jet○ Hazelcast Cloud

@Hazelcastwww.hazelcast.com

Page 4: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

● Introduction● Caching Architectural Patterns

○ Embedded○ Embedded Distributed○ Client-Server○ Cloud○ Sidecar○ Reverse Proxy○ Reverse Proxy Sidecar

● Summary

Agenda

Page 5: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Why Caching?

● Performance○ Decrease latency○ Reduce load

● Resilience○ High availability○ Lower downtime

Page 6: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Service 1

Service 2 v1

Service 2 v2

Service 1

Service 4 v1

Service 4 v2

Service 4 v3

Ruby

Microservice World

Page 7: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Service 1

Service 2 v1

Service 2 v2

Service 1

Service 4 v1

Service 4 v2

Service 4 v3

Ruby

Microservice World

cache

cache

cache

cache

Page 8: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Service 1

Service 2 v1

Service 2 v2

Service 1

Service 4 v1

Service 4 v2

Service 4 v3

Ruby

Microservice Worldcache

cache

cache

Page 9: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Service 1

Service 2 v1

Service 2 v2

Service 1

Service 4 v1

Service 4 v2

Service 4 v3

Ruby

Microservice World

cache

cache

cache

Page 10: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

● Introduction ✔● Caching Architectural Patterns

○ Embedded○ Embedded Distributed○ Client-Server○ Cloud○ Sidecar○ Reverse Proxy○ Reverse Proxy Sidecar

● Summary

Agenda

Page 11: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

1. Embedded

Page 12: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Application

Load Balancer

Cache

Application

Cache

Request

Embedded Cache

Page 13: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

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)

Page 14: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

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)

Page 15: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

● 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!

Page 16: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

CacheBuilder.newBuilder() .initialCapacity(300) .expireAfterAccess(Duration.ofMinutes(10)) .maximumSize(1000) .build();

Embedded Cache (Java libraries)

Page 17: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Embedded Cache (Java libraries)

CacheBuilder.newBuilder() .initialCapacity(300) .expireAfterAccess(Duration.ofMinutes(10)) .maximumSize(1000) .build();

Page 18: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Caching Application Layer

@Servicepublic class BookService {

@Cacheable("books") public String getBookNameByIsbn(String isbn) { return findBookInSlowSource(isbn); }

}

Page 19: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Caching Application Layer

@Servicepublic class BookService {

@Cacheable("books") public String getBookNameByIsbn(String isbn) { return findBookInSlowSource(isbn); }

}

Be Careful, Spring uses ConcurrentHashMap by default!

Page 20: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Application

Load Balancer

Cache

Application

Cache

Request

Embedded Cache

Page 21: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

1*. Embedded Distributed

Page 22: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Application

Application

Load Balancer

Cache

Cache

RequestHazelcast

Cluster

Embedded Distributed Cache

Page 23: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

@Configurationpublic class HazelcastConfiguration {

@Bean CacheManager cacheManager() { return new HazelcastCacheManager( Hazelcast.newHazelcastInstance()); } }

Embedded Distributed Cache (Spring with Hazelcast)

Page 24: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

DEMO

Page 25: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Hazelcast Discovery Plugins

Page 26: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Hazelcast Discovery Plugins

Page 27: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Hazelcast Discovery Plugins

Page 28: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Application

Application

Load Balancer

Cache

Cache

RequestHazelcast

Cluster

Embedded Distributed Cache

Page 29: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

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

Page 30: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

● Introduction ✔● Caching Architectural Patterns

○ Embedded ✔○ Embedded Distributed ✔○ Client-Server○ Cloud○ Sidecar○ Reverse Proxy○ Reverse Proxy Sidecar

● Summary

Agenda

Page 31: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

2. Client-Server

Page 32: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Application

Load Balancer

Application

Request

Cache Server

Client-Server Cache

Page 33: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Application

Load Balancer

Application

Request

Cache Server

Client-Server Cache

Page 34: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Application

Load Balancer

Application

Request

Cache Server

Client-Server CacheSeparate Management:

● backups● (auto) scaling● security

Ops Team

Page 35: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Application

Load Balancer

Application

Request

Cache Server

Client-Server Cache

Page 36: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Application

Load Balancer

Application

Request

Cache Server

Client-Server Cache

Page 37: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Client-Server Cache

Page 38: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Client-Server Cache

Page 39: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Client-Server Cache

$ ./start.sh

Starting Hazelcast Cache Server (standalone)

Page 40: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Client-Server CacheStarting Hazelcast Cache Server (Kubernetes)

$ helm install hazelcast/hazelcast

Page 41: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Client-Server Cache

Hazelcast Client (Kubernetes):

@Configurationpublic class HazelcastClientConfiguration { @Bean CacheManager cacheManager() { ClientConfig clientConfig = new ClientConfig(); clientConfig.getNetworkConfig().getKubernetesConfig() .setEnabled(true); return new HazelcastCacheManager(HazelcastClient .newHazelcastClient(clientConfig)); }}

Starting Hazelcast Cache Server (Kubernetes)

$ helm install hazelcast/hazelcast

Page 42: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Application

Load Balancer

Application

Request

Cache Server

Client-Server Cache

Ops Team

Separate Management:● backups● (auto) scaling● security

Page 43: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

2*. Cloud

Page 44: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Application

Load Balancer

Application

Request

Cloud (Cache as a Service)

Page 45: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Application

Load Balancer

Application

Request

Cloud (Cache as a Service)Management:

● backups● (auto) scaling● security

Ops Team

Page 46: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Application

Load Balancer

Application

Request

Cloud (Cache as a Service)Management:

● backups● (auto) scaling● security

Ops Team

Page 47: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Application

Load Balancer

Application

Request

Cloud (Cache as a Service)

Page 48: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

@Configurationpublic 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)

Page 49: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

DEMOcloud.hazelcast.com

Page 50: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

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)

Page 51: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

● Introduction ✔● Caching Architectural Patterns

○ Embedded ✔○ Embedded Distributed ✔○ Client-Server ✔○ Cloud ✔○ Sidecar○ Reverse Proxy○ Reverse Proxy Sidecar

● Summary

Agenda

Page 52: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

3. Sidecar

Page 53: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Kubernetes Service(Load Balancer)

RequestHazelcast

Cluster

Kubernetes POD

Application Container

Cache Container

Application Container

Cache Container

Kubernetes POD

Sidecar Cache

Page 54: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

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

Page 55: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

@Configurationpublic class HazelcastSidecarConfiguration { @Bean CacheManager cacheManager() { ClientConfig clientConfig = new ClientConfig(); clientConfig.getNetworkConfig() .addAddress("localhost:5701"); return new HazelcastCacheManager(HazelcastClient .newHazelcastClient(clientConfig)); }}

Sidecar Cache

Page 56: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Sidecar Cache

apiVersion: apps/v1kind: Deployment...spec: template: spec: containers: - name: application image: leszko/application - name: hazelcast image: hazelcast/hazelcast

Page 57: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Sidecar Cache Pros Cons

● Simple configuration● Programming-language

agnostic● Low latency● Some isolation of data and

applications

● Limited to container-based environments

● Not flexible management (scaling, backup)

● Data collocated with application PODs

Page 58: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

● Introduction ✔● Caching Architectural Patterns

○ Embedded ✔○ Embedded Distributed ✔○ Client-Server ✔○ Cloud ✔○ Sidecar ✔○ Reverse Proxy○ Reverse Proxy Sidecar

● Summary

Agenda

Page 59: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

4. Reverse Proxy

Page 60: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Application

Load Balancer

Cache

Application

Request

Reverse Proxy Cache

Page 61: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Reverse Proxy Cache

http { ... proxy_cache_path /data/nginx/cache keys_zone=one:10m; ...}

Page 62: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

● Only for HTTP● Not distributed● No High Availability● Data stored on the disk

NGINX Reverse Proxy Cache Issues

Page 63: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

NGINX Reverse Proxy Cache Issues

● Only for HTTP● Not distributed● No High Availability● Data stored on the disk

Page 64: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

4*. Reverse Proxy Sidecar

Page 65: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Kubernetes Service(Load Balancer)

RequestHazelcast

Cluster

Kubernetes POD

Application Container

Reverse Proxy Cache Container

Application Container

Reverse Proxy Cache Container

Kubernetes POD

Reverse Proxy Sidecar Cache

Page 66: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker
Page 67: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Good

Page 68: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Reverse Proxy Sidecar Cache

Service 1

Service 2 v1

Service 2 v2

Service 1

Service 4 v1

Service 4 v2

Service 4 v3

Ruby

Page 69: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Reverse Proxy Sidecar Cache

Service 1

Service 2 v1

Service 2 v2

Service 1

Service 4 v1

Service 4 v2

Service 4 v3

Ruby

Page 70: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Reverse Proxy Sidecar CacheapiVersion: apps/v1kind: Deployment...spec: template: spec: initContainers: - name: init-networking image: leszko/init-networking containers: - name: caching-proxy image: leszko/caching-proxy - name: application image: leszko/application

Page 71: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Reverse Proxy Cache

Container

ApplicationContainer

eth0:80

Reverse Proxy Sidecar Cache

:80

Pod

:8000

lo:80

Page 72: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Reverse Proxy Sidecar Cache#!/bin/bash

# Forward TCP traffic on port 80 to port 8000 on the eth0 interface.iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 80 -j REDIRECT --to-port 8000

Page 73: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Reverse Proxy Sidecar Cache

Service 1

Service 2 v1

Service 2 v2

Service 1

Service 4 v1

Service 4 v2

Service 4 v3

Ruby

Page 74: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker
Page 75: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Reverse Proxy Sidecar Cache (Istio)

Page 76: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Bad

Page 77: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker
Page 78: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Reverse Proxy Cache

@CacheEvict(value = "someValue", allEntries = true)public void evictAllCacheValues() {}

Application Cache:

Page 79: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

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; }}

Page 80: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

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)

Page 81: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

● Introduction ✔● Caching Architectural Patterns

○ Embedded ✔○ Embedded Distributed ✔○ Client-Server ✔○ Cloud ✔○ Sidecar ✔○ Reverse Proxy ✔○ Reverse Proxy Sidecar ✔

● Summary

Agenda

Page 82: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Summary

Page 83: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

application-aware?

Page 84: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

application-aware?

containers?

no

Page 85: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

application-aware?

containers?

Reverse Proxy

no

no

Page 86: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

application-aware?

containers?

Reverse ProxyReverse Proxy Sidecar

no

yes no

Page 87: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

application-aware?

containers?

Reverse ProxyReverse Proxy Sidecar

lot of data?security restrictions?

yes no

yes no

Page 88: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

application-aware?

containers?

Reverse ProxyReverse Proxy Sidecar

lot of data?security restrictions?

language-agnostic? containers?

yes no

yes nono

Page 89: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

application-aware?

containers?

Reverse ProxyReverse Proxy Sidecar

lot of data?security restrictions?

language-agnostic? containers?

Embedded (Distributed)

yes no

yes no

no

no

Page 90: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

application-aware?

containers?

Reverse ProxyReverse Proxy Sidecar

lot of data?security restrictions?

language-agnostic? containers?

Embedded (Distributed)

Sidecar

yes no

yes

yes no

no

no

Page 91: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

application-aware?

containers?

Reverse ProxyReverse Proxy Sidecar

lot of data?security restrictions?

language-agnostic? containers?

Embedded (Distributed)

Sidecar

cloud?

yes no

yes

yes

yes no

no

no

Page 92: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

application-aware?

containers?

Reverse ProxyReverse Proxy Sidecar

lot of data?security restrictions?

language-agnostic? containers?

Embedded (Distributed)

Sidecar

cloud?

Client-Server

yes no

yes

yes

yes no

nono

no

Page 93: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

application-aware?

containers?

Reverse ProxyReverse Proxy Sidecar

lot of data?security restrictions?

language-agnostic? containers?

Embedded (Distributed)

Sidecar

cloud?

Client-ServerCloud

yes no

yes

yes yes

yes no

nono

no

Page 94: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

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/

Page 95: Architectural patterns for caching microservices by …...About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book "Continuous Delivery with Docker

Thank You!Rafał Leszko

@RafalLeszkorafalleszko.com