O slideshow foi denunciado.
Seu SlideShare está sendo baixado. ×

Building real-time applications with Amazon ElastiCache - ADB204 - Anaheim AWS Summit

Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Carregando em…3
×

Confira estes a seguir

1 de 38 Anúncio

Building real-time applications with Amazon ElastiCache - ADB204 - Anaheim AWS Summit

Baixar para ler offline

In this session, we give an overview of how to build low-latency and high-throughput applications with Amazon ElastiCache. We also provide an introduction to Redis and Memcached, two of the world’s leading in-memory databases, and we cover the specific use cases customers are solving with them. From use cases like caching, session storage, and leaderboards, a wide range of applications can have dramatic performance improvements with an added an in-memory database.

In this session, we give an overview of how to build low-latency and high-throughput applications with Amazon ElastiCache. We also provide an introduction to Redis and Memcached, two of the world’s leading in-memory databases, and we cover the specific use cases customers are solving with them. From use cases like caching, session storage, and leaderboards, a wide range of applications can have dramatic performance improvements with an added an in-memory database.

Anúncio
Anúncio

Mais Conteúdo rRelacionado

Diapositivos para si (20)

Semelhante a Building real-time applications with Amazon ElastiCache - ADB204 - Anaheim AWS Summit (20)

Anúncio

Mais de Amazon Web Services (20)

Building real-time applications with Amazon ElastiCache - ADB204 - Anaheim AWS Summit

  1. 1. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Building real-time applications with Amazon ElastiCache Madelyn Olson Software development engineer AWS A D B 2 0 4
  2. 2. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Real-time apps need low latency and high throughput Users: 1 million+ Data volume: TB Locality: Global Performance: Microseconds Request rate: Millions Access: Mobile, Internet of Things (IoT), Microservices Scale: Up-out-in Economics: Pay as you go Developer access: Open APIs Social mediaRide hailing Media streaming Social mediaRide hailing Media streaming Gaming leaderboards
  3. 3. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Redis and Memcached—Top two in-memory data store* * https://db-engines.com/en/ranking, https://insights.stackoverflow.com/survey/2018/
  4. 4. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T About Redis Simple • Commands • Client support Fast • In-memory • <1ms Powerful • Various data types • Atomic operations • LRU/LFU/TTL Scalable • High availability • Backups • Cluster
  5. 5. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T About Memcached Multi-threaded • Easy to scale Fast • In-memory • < 1ms Established • Launched in 2003 Simple • LRU cache • Key-value
  6. 6. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Difficult to scale Difficult to manage and secure Hard to make highly available Self-managing Redis and Memcached is challenging Expensive Online scaling can be error prone, replication performance needs to be monitored Manage hardware provisioning, setup, configuration, backups, and compliance (security, encryption, patching) Invest in people, processes, hardware, and software Need to implement fast error detection and remediation
  7. 7. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T ElastiCache for Redis and Memcached Fully-managed, open-sourcecompatible, in-memorydata storein the cloud Extreme performance In-memory data store and cache for sub-millisecond response times Platform tuning and optimization (e.g., R5/M5) Fully managed AWS manages all hardware and software setup, configuration, monitoring Easily scalable Read scaling with replicas Write and memory scaling with sharding (up to 250 nodes/170 TB of data) OSS-compatible Redis 5 support Memcached 1.5 support Client compatible Reliable Multi-AZ Deep monitoring Automatic failover Secure and compliant Amazon Virtual Private Cloud HIPAA, PCI, FedRAMP Encryption at-rest and in-transit Authentication
  8. 8. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T When to use which ElastiCache databases ElastiCache Redis (Default) ElastiCache Memcached Primary use case In-memory database and cache Cache Data model In-memory key-value In-memory key-value Open source compatibility Redis Memcached Cache databases compatibility All databases All databases Cache size 155.17 TiB 12.7 TiB Data structures Strings, lists, sets, sorted sets, hashes, bit arrays, HyperLogLog Strings, objects Commands 200+ Get, set, stats, add, replace, flush all High availability and failover Yes No Eviction policies Advanced eviction policies no eviction, allkeys-lru, volatile-lru, allkeys-random, volatile-random, volatile-ttl Least recently used (LRU)
  9. 9. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Grab is Southeast Asia’s largest ride-hailing service with 45 million downloads and 2.5 million daily rides Challenge: Average response time of the API layer is < 40 ms Solution: ElastiCache for Redis as a caching layer on Amazon Relational Database Service (Amazon RDS) for MySQL provides sub-millisecond latency even in times of peak traffic of hundreds of thousands of cab requests per minute
  10. 10. S U M M I T © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  11. 11. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Use cases Gaming leaderboards Chat apps Caching Session store Machine learning Real-time analytics Media streaming Message queues Geospatial
  12. 12. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Challenge: Retrieving data from disk- based databases and applications is slow. Workarounds such as specialized hardware, proprietary in-memory databases, and data reduction are expensive, have high lock-in, don’t scale, and are difficult to manage. Solution: Use Redis, an open source, in-memory data store and cache, to store frequently used data in-memory for microsecond latency and high throughput. Use cases: Database query caching, persistent session caching, and full web-page caching.
  13. 13. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Clients Cache reads/writes DB reads/writes ✓ Better performance – Microsecond speed ✓ Cost effective ✓ Higher throughput – ~50 million RPS Caching
  14. 14. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Monitoring CacheMisses/CacheHits: Successful retrievals Reclaimed: Number of keys that have expired Evictions: Keys removed due to memory limits
  15. 15. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Challenge: Need low-latency and high- concurrency data stores to process fast- moving ephemeral session data such as authentication tokens, cookies, and session state. Solution: Use Redis as an in-memory key-value store and cache with appropriate key expiration strategies to store and manage ephemeral session data for microsecond responses. Apps: Web and mobile apps. Session store
  16. 16. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Challenge: Leaderboards need low- latency and high-concurrency data stores to process changing scores and update ranks in real-time. Solution: Use Redis as an in-memory data store with data structures such as sorted sets and ranked lists that ensure uniqueness of elements while maintaining lists sorted by scores with microsecond latency. Apps: Gaming leaderboards, sales leaderboards.
  17. 17. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Redis data type—Sorted sets • A set of unique items that all have a corresponding score • Similar to an index • Fast lookup and ranges based on the score • Based on a probabilistic skip list with set • Primitive add and remove with: ZADD and ZREM • Scanning and searching with: ZRANGE and ZRANGEBYSCORE
  18. 18. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Leaderboard example—Sorted set Populating a leaderboard > zadd leaderboard 556 Andy > zadd leaderboard 819 Barry > zadd leaderboard 105 Carl > zadd leaderboard 1312 Derek Updating a leaderboard > zadd leaderboard 1502 Carl > zrevrange leaderboard 0 -1 1) "Carl" 2) "Derek" 3) "Barry" 4) "Andy" Querying a leaderboard > zrevrange leaderboard 0 -1 1) "Derek" 2) "Barry" 3) "Andy" 4) "Carl" > zrevrank leaderboard Barry 1 Score Name Start index End index
  19. 19. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Challenge: Need a fast data store to process fast-moving streaming data in real-time. Solution: Use Redis as an in-memory data store with versatile data structures such as streams, lists, and sets to ingest, process, and analyze real-time data with sub-millisecond latency. Apps: Social media, ad targeting, personalization, IoT, and time-series data analytics. Real-time streaming and analytics store
  20. 20. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Streaming data access Hot data Longer retention Data sources 1
  21. 21. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Native streaming data type—Redis streams New data type (Redis 5.0) Push and pop values like list; supports lookup by ID Implemented with Rax A Radix library tree optimized for fast lookups and range queries Consumer groups Multiple producers and consumers can interact with the same queue Start End Consumer 1 Consumer 2 Consumer A Consumer B
  22. 22. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Redis streams example > XADD locstream * device1 123456 latitude 48.858372 longitude 2.294481 1549057272661-0 > XREAD STREAMS locstream 0 1) 1) "locstream" 2) 1) 1) 1549057272661-0 2) ... > XREAD STREAMS locstream 1549057272661-0 (nil) Autogenerate ID Properties Last ID processed Same ID
  23. 23. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Challenge: Chat and messaging apps require a low-latency and high- throughput communication channel over which a client can send messages that are redistributed to other participants. Solution: Use Redis as an in-memory store and cache with Redis Streams and pub/sub features to build high- performance chat and messaging apps. Apps: Chat rooms, comment streams, machine-to-machine communication.
  24. 24. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Redis pub/sub • Messages are categorized into channels • Subscribers can subscribe to multiple patterns or channels • Publishers publish to a given channel • Messages are not stored anywhere • Clients must be connected to receive • Two main commands: PUBLISH and SUBSCRIBE
  25. 25. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Chat and messaging example—Pub/sub > psubscribe sports:* Reading messages... 1) "psubscribe" 2) "sports:*" 3) (integer) 1 > publish sports:patriots "Goooo team!" (integer) 1 1) "pmessage" 2) "sports:*" 3) "sports:patriots" 4) "Goooo team!"
  26. 26. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Challenge: Need low-latency and high-concurrency data stores to process fast-moving location data in real-time. Solution: Use Redis as an in-memory data store with purpose-built data structures such as sorted sets, encoding/decoding of location data, and APIs for location-specific indexing, searching, and sorting. Apps: Ride-hailing, dating, social media, gaming, e-commerce. Geospatial apps
  27. 27. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Geospatial enrichment Frontend application Restaurant geospatial data Friend relationship graph Query friend recommendations Query nearby recommended restaurants Query nearby restaurants > GEORADIUS restaurants 47.6062 122.3321 10 mi 1) "Starbucks" 2) "McDonalds" 3) "The Best Burger Place" Lat/Long Distance
  28. 28. S U M M I T © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  29. 29. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Peloton is the leading in-home fitness company Challenge: Leaderboard requires elasticity, low latency, and real-time processing to deliver customizable rider data for thousands of users riding together from the comfort of their homes. Solution: ElastiCache for Redis as an in-memory data store provides scale and performance to process streaming data for on-demand, live leaderboard.
  30. 30. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Expedia is a leader in the $1 trillion travel industry, with an extensive portfolio of brands Challenge: Need in-memory data store and cache for real- time analytics application that processes ~200 million messages daily. Solution: ElastiCache for Redis as an in-memory data store and cache to speed up data ingest and analytics.
  31. 31. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Challenge: Large surge event for a new feature launch on Fortnite required scaling Redis clusters. Solution: ElastiCache for Redis with online cluster resizing to dynamically scale out and scale in. Migrated to optimized R5 instances for higher throughput, superior performance, and managing traffic spikes. Epic Games—ElastiCache to manage surge events
  32. 32. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Challenge: Scale the business to the next level with three times data growth every year and petabytes of data stored. Need to quickly process and analyze 50 GB of data daily. Solution: Airbnb adopted purpose-built databases for different needs. Session state: ElastiCache for in-memory store for sub-millisecond session access.
  33. 33. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Software and Internet Financial Ser vicesRide-Hailing Gaming Media and Entertainment Social Media Telecommunications Travel Industrials and Ser vices Logistics and Operations Publishing Other ElastiCache customers
  34. 34. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Redis page aws.amazon.com/redis ElastiCache for Redis page aws.amazon.com/elasticache/redis ElastiCache for Memcached page https://aws.amazon.com/elasticache/memcached/ Contact us aws.amazon.com/contact-us/ Get started
  35. 35. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Thank you! S U M M I T © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved. Madelyn Olson
  36. 36. S U M M I T © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
  37. 37. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T 1) Install php, apache php redis client (e.g., yum install php apache php-pecl-redis) 2) Configure “php.ini” session.save_handler = rediscluster session.save_path = " seed[]=cluster-discovery-endpoint:6379& timeout=2& read_timeout=2& failover=error& persistent=1" 3) Restart httpd 4) Begin using session data For situations where you need an external session store: • Especially needed when using ASGs • Cache is optimal for high-volume reads PHP Example Session Store Details Auto scaling Instances
  38. 38. © 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.S U M M I T Example Caching Application # App code save_user(17, {"name": “John Doe"}) user = get_user(17) # Write Through def save_user(user_id, values): record = db.query("update users ... where id = ?", user_id, values) cache.set(user_id, record, 300) # TTL return record # Lazy Load def get_user(user_id): record = cache.get(user_id) if record is None: record = db.query("select * from users where id = ?", user_id) cache.set(user_id, record, 300) # TTL return record Write through 1. Updated DB 2. SET in cache Lazy load 1. GET from cache. 2. If MISS get from DB 3. Then SET in cache

×