Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

of

Architectural caching patterns for kubernetes Slide 1 Architectural caching patterns for kubernetes Slide 2 Architectural caching patterns for kubernetes Slide 3 Architectural caching patterns for kubernetes Slide 4 Architectural caching patterns for kubernetes Slide 5 Architectural caching patterns for kubernetes Slide 6 Architectural caching patterns for kubernetes Slide 7 Architectural caching patterns for kubernetes Slide 8 Architectural caching patterns for kubernetes Slide 9 Architectural caching patterns for kubernetes Slide 10 Architectural caching patterns for kubernetes Slide 11 Architectural caching patterns for kubernetes Slide 12 Architectural caching patterns for kubernetes Slide 13 Architectural caching patterns for kubernetes Slide 14 Architectural caching patterns for kubernetes Slide 15 Architectural caching patterns for kubernetes Slide 16 Architectural caching patterns for kubernetes Slide 17 Architectural caching patterns for kubernetes Slide 18 Architectural caching patterns for kubernetes Slide 19 Architectural caching patterns for kubernetes Slide 20 Architectural caching patterns for kubernetes Slide 21 Architectural caching patterns for kubernetes Slide 22 Architectural caching patterns for kubernetes Slide 23 Architectural caching patterns for kubernetes Slide 24 Architectural caching patterns for kubernetes Slide 25 Architectural caching patterns for kubernetes Slide 26 Architectural caching patterns for kubernetes Slide 27 Architectural caching patterns for kubernetes Slide 28 Architectural caching patterns for kubernetes Slide 29 Architectural caching patterns for kubernetes Slide 30 Architectural caching patterns for kubernetes Slide 31 Architectural caching patterns for kubernetes Slide 32 Architectural caching patterns for kubernetes Slide 33 Architectural caching patterns for kubernetes Slide 34 Architectural caching patterns for kubernetes Slide 35 Architectural caching patterns for kubernetes Slide 36 Architectural caching patterns for kubernetes Slide 37 Architectural caching patterns for kubernetes Slide 38 Architectural caching patterns for kubernetes Slide 39 Architectural caching patterns for kubernetes Slide 40 Architectural caching patterns for kubernetes Slide 41 Architectural caching patterns for kubernetes Slide 42 Architectural caching patterns for kubernetes Slide 43 Architectural caching patterns for kubernetes Slide 44 Architectural caching patterns for kubernetes Slide 45 Architectural caching patterns for kubernetes Slide 46 Architectural caching patterns for kubernetes Slide 47 Architectural caching patterns for kubernetes Slide 48 Architectural caching patterns for kubernetes Slide 49 Architectural caching patterns for kubernetes Slide 50 Architectural caching patterns for kubernetes Slide 51 Architectural caching patterns for kubernetes Slide 52 Architectural caching patterns for kubernetes Slide 53 Architectural caching patterns for kubernetes Slide 54 Architectural caching patterns for kubernetes Slide 55 Architectural caching patterns for kubernetes Slide 56 Architectural caching patterns for kubernetes Slide 57 Architectural caching patterns for kubernetes Slide 58 Architectural caching patterns for kubernetes Slide 59 Architectural caching patterns for kubernetes Slide 60 Architectural caching patterns for kubernetes Slide 61 Architectural caching patterns for kubernetes Slide 62 Architectural caching patterns for kubernetes Slide 63 Architectural caching patterns for kubernetes Slide 64 Architectural caching patterns for kubernetes Slide 65 Architectural caching patterns for kubernetes Slide 66 Architectural caching patterns for kubernetes Slide 67 Architectural caching patterns for kubernetes Slide 68 Architectural caching patterns for kubernetes Slide 69 Architectural caching patterns for kubernetes Slide 70 Architectural caching patterns for kubernetes Slide 71 Architectural caching patterns for kubernetes Slide 72 Architectural caching patterns for kubernetes Slide 73 Architectural caching patterns for kubernetes Slide 74 Architectural caching patterns for kubernetes Slide 75 Architectural caching patterns for kubernetes Slide 76 Architectural caching patterns for kubernetes Slide 77 Architectural caching patterns for kubernetes Slide 78 Architectural caching patterns for kubernetes Slide 79 Architectural caching patterns for kubernetes Slide 80 Architectural caching patterns for kubernetes Slide 81 Architectural caching patterns for kubernetes Slide 82 Architectural caching patterns for kubernetes Slide 83
Upcoming SlideShare
What to Upload to SlideShare
Next
Download to read offline and view in fullscreen.

0 Likes

Share

Download to read offline

Architectural caching patterns for kubernetes

Download to read offline

https://www2.slideshare.net/RafaLeszko/build-your-operator-with-the-right-tool

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all
  • Be the first to like this

Architectural caching patterns for kubernetes

  1. 1. Architectural Caching Patterns for Kubernetes Rafał Leszko @RafalLeszko rafalleszko.com Hazelcast
  2. 2. 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
  3. 3. About Hazelcast ● Distributed Company ● Open Source Software ● 140+ Employees ● Products: ○ Hazelcast IMDG ○ Hazelcast Jet ○ Hazelcast Cloud @Hazelcast www.hazelcast.com
  4. 4. ● Introduction ● Caching Architectural Patterns ○ Embedded ○ Embedded Distributed ○ Client-Server ○ Cloud ○ Sidecar ○ Reverse Proxy ○ Reverse Proxy Sidecar ● Summary Agenda
  5. 5. Service 1 Service 2 v1 Service 2 v2 Service 1 Service 4 v1 Service 4 v2 Service 4 v3 Ruby Microservice World
  6. 6. 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
  7. 7. 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
  8. 8. 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
  9. 9. ● Introduction ✔ ● Caching Architectural Patterns ○ Embedded ○ Embedded Distributed ○ Client-Server ○ Cloud ○ Sidecar ○ Reverse Proxy ○ Reverse Proxy Sidecar ● Summary Agenda
  10. 10. 1. Embedded
  11. 11. Application Kubernetes Service Cache Application Cache Request Embedded Cache Kubernetes Pod Kubernetes Pod
  12. 12. 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)
  13. 13. 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)
  14. 14. ● 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!
  15. 15. CacheBuilder.newBuilder() .initialCapacity(300) .expireAfterAccess(Duration.ofMinutes(10)) .maximumSize(1000) .build(); Embedded Cache (Java libraries)
  16. 16. Embedded Cache (Java libraries) CacheBuilder.newBuilder() .initialCapacity(300) .expireAfterAccess(Duration.ofMinutes(10)) .maximumSize(1000) .build();
  17. 17. Caching Application Layer @Service public class BookService { @Cacheable("books") public String getBookNameByIsbn(String isbn) { return findBookInSlowSource(isbn); } }
  18. 18. Caching Application Layer @Service public class BookService { @Cacheable("books") public String getBookNameByIsbn(String isbn) { return findBookInSlowSource(isbn); } } Be Careful, Spring uses ConcurrentHashMap by default!
  19. 19. Embedded Cache Application Kubernetes Service Cache Application Cache Request Kubernetes Pod Kubernetes Pod
  20. 20. 1*. Embedded Distributed
  21. 21. Application Application Kubernetes Service Cache Cache Request Hazelcast Cluster Embedded Distributed Cache Kubernetes Pod Kubernetes Pod
  22. 22. @Configuration public class HazelcastConfiguration { @Bean CacheManager cacheManager() { return new HazelcastCacheManager( Hazelcast.newHazelcastInstance()); } } Embedded Distributed Cache (Spring with Hazelcast)
  23. 23. Hazelcast Discovery Plugins
  24. 24. Hazelcast Discovery Plugins
  25. 25. Embedded Distributed Cache Application Application Kubernetes Service Cache Cache Request Hazelcast Cluster Kubernetes Pod Kubernetes Pod
  26. 26. 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
  27. 27. ● Introduction ✔ ● Caching Architectural Patterns ○ Embedded ✔ ○ Embedded Distributed ✔ ○ Client-Server ○ Cloud ○ Sidecar ○ Reverse Proxy ○ Reverse Proxy Sidecar ● Summary Agenda
  28. 28. 2. Client-Server
  29. 29. Application Kubernetes Service Application Request Cache Server StatefulSet Client-Server Cache Kubernetes Pod Kubernetes Pod
  30. 30. Client-Server Cache Application Kubernetes Service Application Request Cache Server StatefulSet Kubernetes Pod Kubernetes Pod
  31. 31. Client-Server Cache Separate Management: ● backups ● (auto) scaling ● security Ops Team Application Kubernetes Service Application Request Cache Server StatefulSet Kubernetes Pod Kubernetes Pod
  32. 32. Client-Server Cache Application Kubernetes Service Application Request Cache Server StatefulSet Kubernetes Pod Kubernetes Pod
  33. 33. Client-Server Cache Application Kubernetes Service Application Request Cache Server StatefulSet Kubernetes Pod Kubernetes Pod
  34. 34. Client-Server Cache
  35. 35. Client-Server Cache
  36. 36. Client-Server Cache Starting Hazelcast Cache Server $ helm install hazelcast/hazelcast
  37. 37. 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
  38. 38. Client-Server Cache Separate Management: ● backups ● (auto) scaling ● security Ops Team Application Kubernetes Service Application Request Cache Server StatefulSet Kubernetes Pod Kubernetes Pod
  39. 39. 2*. Cloud
  40. 40. Application Kubernetes Service Application Request Cloud (Cache as a Service) Kubernetes Pod Kubernetes Pod
  41. 41. Cloud (Cache as a Service) Management: ● backups ● (auto) scaling ● security Ops Team Application Kubernetes Service Application Request Kubernetes Pod Kubernetes Pod
  42. 42. Cloud (Cache as a Service) Management: ● backups ● (auto) scaling ● security Ops Team Application Kubernetes Service Application Request Kubernetes Pod Kubernetes Pod
  43. 43. Cloud (Cache as a Service) Application Kubernetes Service Application Request Kubernetes Pod Kubernetes Pod
  44. 44. @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)
  45. 45. 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)
  46. 46. ● Introduction ✔ ● Caching Architectural Patterns ○ Embedded ✔ ○ Embedded Distributed ✔ ○ Client-Server ✔ ○ Cloud ✔ ○ Sidecar ○ Reverse Proxy ○ Reverse Proxy Sidecar ● Summary Agenda
  47. 47. 3. Sidecar
  48. 48. Kubernetes Service Request Hazelcast Cluster Kubernetes POD Application Container Cache Container Application Container Cache Container Kubernetes POD Sidecar Cache
  49. 49. 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
  50. 50. @Configuration public class HazelcastSidecarConfiguration { @Bean CacheManager cacheManager() { ClientConfig clientConfig = new ClientConfig(); clientConfig.getNetworkConfig() .addAddress("localhost:5701"); return new HazelcastCacheManager(HazelcastClient .newHazelcastClient(clientConfig)); } } Sidecar Cache
  51. 51. Sidecar Cache apiVersion: apps/v1 kind: Deployment ... spec: template: spec: containers: - name: application image: leszko/application - name: hazelcast image: hazelcast/hazelcast
  52. 52. 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
  53. 53. ● Introduction ✔ ● Caching Architectural Patterns ○ Embedded ✔ ○ Embedded Distributed ✔ ○ Client-Server ✔ ○ Cloud ✔ ○ Sidecar ✔ ○ Reverse Proxy ○ Reverse Proxy Sidecar ● Summary Agenda
  54. 54. 4. Reverse Proxy
  55. 55. Application Kubernetes Service Cache Application Request Reverse Proxy Cache Kubernetes Pod Kubernetes Pod
  56. 56. Reverse Proxy Cache http { ... proxy_cache_path /data/nginx/cache keys_zone=one:10m; ... }
  57. 57. ● Only for HTTP ● Not distributed ● No High Availability ● Data stored on the disk NGINX Reverse Proxy Cache Issues
  58. 58. 4*. Reverse Proxy Sidecar
  59. 59. 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
  60. 60. Good
  61. 61. Reverse Proxy Sidecar Cache Service 1 Service 2 v1 Service 2 v2 Service 1 Service 4 v1 Service 4 v2 Service 4 v3 Ruby
  62. 62. Reverse Proxy Sidecar Cache Service 1 Service 2 v1 Service 2 v2 Service 1 Service 4 v1 Service 4 v2 Service 4 v3 Ruby
  63. 63. Bad
  64. 64. Reverse Proxy Cache @CacheEvict(value = "someValue", allEntries = true) public void evictAllCacheValues() {} Application Cache:
  65. 65. 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; } }
  66. 66. 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)
  67. 67. ● Introduction ✔ ● Caching Architectural Patterns ○ Embedded ✔ ○ Embedded Distributed ✔ ○ Client-Server ✔ ○ Cloud ✔ ○ Sidecar ✔ ○ Reverse Proxy ✔ ○ Reverse Proxy Sidecar ✔ ● Summary Agenda
  68. 68. Summary
  69. 69. application-aware?
  70. 70. application-aware? early adopter? no
  71. 71. application-aware? Reverse Proxy no no early adopter?
  72. 72. application-aware? Reverse Proxy Reverse Proxy Sidecar no yes no early adopter?
  73. 73. application-aware? Reverse Proxy Reverse Proxy Sidecar lot of data? security restrictions? yes no yes no early adopter?
  74. 74. application-aware? Reverse Proxy Reverse Proxy Sidecar lot of data? security restrictions? language-agnostic? yes no yes nono early adopter?
  75. 75. application-aware? Reverse Proxy Reverse Proxy Sidecar lot of data? security restrictions? language-agnostic? Embedded (Distributed) yes no yes no no no early adopter?
  76. 76. 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?
  77. 77. 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?
  78. 78. 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?
  79. 79. 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?
  80. 80. 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/
  81. 81. Thank You! Rafał Leszko @RafalLeszko

https://www2.slideshare.net/RafaLeszko/build-your-operator-with-the-right-tool

Views

Total views

149

On Slideshare

0

From embeds

0

Number of embeds

0

Actions

Downloads

2

Shares

0

Comments

0

Likes

0

×