where is my cache architectural patterns for caching
play

Where is my cache? Architectural patterns for caching microservices - PowerPoint PPT Presentation

Where is my cache? Architectural patterns for caching microservices by example Rafa Leszko Cloud Software Engineer Hazelcast About me Cloud Software Engineer at Hazelcast Worked at Google and CERN Author of the book


  1. Where is my cache? Architectural patterns for caching microservices by example Rafał Leszko Cloud Software Engineer Hazelcast

  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. About Hazelcast ● Distributed Company ● Open Source Software ● 140+ Employees ● Hiring (Remote)! ● Recently Raised $21M ● Products: ○ Hazelcast IMDG @Hazelcast ○ Hazelcast Jet ○ Hazelcast Cloud www.hazelcast.com

  4. Agenda ● Introduction ● Caching Architectural Patterns ○ Embedded ○ Embedded Distributed ○ Client-Server ○ Cloud ○ Sidecar ○ Reverse Proxy ○ Reverse Proxy Sidecar ● Summary

  5. Why Caching? ● Performance ○ Decrease latency ○ Reduce load ● Resilience ○ High availability ○ Lower downtime

  6. Microservice World Service 2 v1 Service 2 v2 Service 1 Service 4 v1 Service 4 v2 Service 1 Service 4 v3 Ruby

  7. Microservice World Service 2 v1 cache Service 2 v2 cache cache Service 1 Service 4 v1 Service 4 v2 Service 1 cache Service 4 v3 Ruby

  8. Microservice World cache cache cache Service 2 v1 Service 2 v2 Service 1 Service 4 v1 Service 4 v2 Service 1 Service 4 v3 Ruby

  9. Microservice World Service 2 v1 cache Service 2 v2 cache Service 1 Service 4 v1 Service 4 v2 cache Service 1 Service 4 v3 Ruby

  10. Agenda ● Introduction ● Caching Architectural Patterns ○ Embedded ○ Embedded Distributed ○ Client-Server ○ Cloud ○ Sidecar ○ Reverse Proxy ○ Reverse Proxy Sidecar ● Summary

  11. 1. Embedded

  12. Embedded Cache Application Cache Request Load Balancer Application Cache

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

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

  15. Java Collection is not a Cache! ● No Eviction Policies ● No Max Size Limit (OutOfMemoryError) ● No Statistics ● No built-in Cache Loaders ● No Expiration Time ● No Notification Mechanism

  16. Embedded Cache (Java libraries) CacheBuilder. newBuilder () .initialCapacity(300) .expireAfterAccess(Duration. ofMinutes (10)) .maximumSize(1000) .build();

  17. Embedded Cache (Java libraries) CacheBuilder. newBuilder () .initialCapacity(300) .expireAfterAccess(Duration. ofMinutes (10)) .maximumSize(1000) .build();

  18. Caching Application Layer @Service public class BookService { @Cacheable( "books" ) public String getBookNameByIsbn(String isbn) { return findBookInSlowSource(isbn); } }

  19. Caching Application Layer @Service public class BookService { @Cacheable( "books" ) public String getBookNameByIsbn(String isbn) { return findBookInSlowSource(isbn); } } Be Careful, Spring uses ConcurrentHashMap by default!

  20. Embedded Cache Application Cache Request Load Balancer Application Cache

  21. 1*. Embedded Distributed

  22. Embedded Distributed Cache Application Hazelcast Cache Request Cluster Load Balancer Cache Application

  23. Embedded Distributed Cache (Spring with Hazelcast) @Configuration public class HazelcastConfiguration { @Bean CacheManager cacheManager() { return new HazelcastCacheManager( Hazelcast. newHazelcastInstance ()); } }

  24. DEMO

  25. Hazelcast Discovery Plugins

  26. Hazelcast Discovery Plugins

  27. Hazelcast Discovery Plugins

  28. Embedded Distributed Cache Application Hazelcast Cache Request Cluster Load Balancer Cache Application

  29. Embedded Cache Pros Cons ● Not flexible management (scaling, ● Simple configuration / deployment backup) ● Low-latency data access ● Limited to JVM-based ● No separate Ops Team needed applications ● Data collocated with applications

  30. Agenda ● Introduction ● Caching Architectural Patterns ○ Embedded ○ Embedded Distributed ○ Client-Server ○ Cloud ○ Sidecar ○ Reverse Proxy ○ Reverse Proxy Sidecar ● Summary

  31. 2. Client-Server

  32. Client-Server Cache Cache Server Application Request Load Balancer Application

  33. Client-Server Cache Cache Server Application Request Load Balancer Application

  34. Separate Management: Client-Server Cache ● backups ● (auto) scaling ● security Cache Server Application Request Load Balancer Application Ops Team

  35. Client-Server Cache Cache Server Application Request Load Balancer Application

  36. Client-Server Cache Cache Server Application Request Load Balancer Application

  37. Client-Server Cache

  38. Client-Server Cache

  39. Client-Server Cache Starting Hazelcast Cache Server (standalone) $ ./start.sh

  40. Client-Server Cache Starting Hazelcast Cache Server (Kubernetes) $ helm install hazelcast/hazelcast

  41. Client-Server Cache Starting Hazelcast Cache Server (Kubernetes) $ helm install hazelcast/hazelcast Hazelcast Client (Kubernetes): @Configuration public class HazelcastClientConfiguration { @Bean CacheManager cacheManager() { ClientConfig clientConfig = new ClientConfig(); clientConfig.getNetworkConfig().getKubernetesConfig() .setEnabled( true ); return new HazelcastCacheManager(HazelcastClient . newHazelcastClient (clientConfig)); } }

  42. Separate Management: Client-Server Cache ● backups ● (auto) scaling ● security Cache Server Application Request Load Balancer Application Ops Team

  43. 2*. Cloud

  44. Cloud (Cache as a Service) Application Request Load Balancer Application

  45. Cloud (Cache as a Service) Management: ● backups ● (auto) scaling ● security Application Request Load Balancer Application Ops Team

  46. Cloud (Cache as a Service) Management: ● backups ● (auto) scaling ● security Application Request Load Balancer Application Ops Team

  47. Cloud (Cache as a Service) Application Request Load Balancer Application

  48. Cloud (Cache as a Service) @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)); } }

  49. DEMO cloud.hazelcast.com

  50. Client-Server (Cloud) Cache Pros Cons ● Data separate from applications ● Separate Ops effort ● Separate management (scaling, ● Higher latency backup) ● Server network requires ● Programming-language agnostic adjustment (same region, same VPC)

  51. Agenda ● Introduction ● Caching Architectural Patterns ○ Embedded ○ Embedded Distributed ○ Client-Server ○ Cloud ○ Sidecar ○ Reverse Proxy ○ Reverse Proxy Sidecar ● Summary

  52. 3. Sidecar

  53. Sidecar Cache Kubernetes POD Application Container Cache Container Hazelcast Request Cluster Kubernetes Service (Load Balancer) Cache Container Application Container Kubernetes POD

  54. Sidecar Cache Similar to Embedded : Similar to Client-Server : ● the same physical machine ● different programming language ● the same resource pool ● uses cache client to connect ● scales up and down together ● clear isolation between app and cache ● no discovery needed (always localhost)

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

  56. Sidecar Cache apiVersion : apps/v1 kind : Deployment ... spec : template : spec : containers : - name : application image : leszko/application - name : hazelcast image : hazelcast/hazelcast

  57. Sidecar Cache Pros Cons ● Simple configuration ● Limited to container-based ● Programming-language agnostic environments ● Low latency ● Not flexible management (scaling, ● Some isolation of data and backup) applications ● Data collocated with application PODs

  58. Agenda ● Introduction ● Caching Architectural Patterns ○ Embedded ○ Embedded Distributed ○ Client-Server ○ Cloud ○ Sidecar ○ Reverse Proxy ○ Reverse Proxy Sidecar ● Summary

  59. 4. Reverse Proxy

  60. Reverse Proxy Cache Application Request Load Balancer Cache Application

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

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend