SlideShare a Scribd company logo
1 of 29
Download to read offline
Serverless 

Multi Region Caching
Kurt Lee
Technical Leader, Vingle Inc
iOS / Frontend / Backend
kurt@vingle.net
https://github.com/breath103
© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
Vingle, Interest Network
© 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
Q. What’s the point of doing multi region without local cache
Things That Will Not Be Covered
a. Why Master-Master Multi Region is SO HARD
b. How to migrate Monolith to Microservice
c. How to migrate to Serverless (Lambda)
Things That Will Be Covered
a. How to build multi-region cache replication
b. Include monitoring / backup
c. in Serverless
CDN
AP-NORTHEAST-2
User
US-EAST-1
CDN Edge (Lambda)
Edge (Lambda)
Memcached
Memcached
Feed
User
Card
Scenario
1) Someone request User A’s profile image from VIRGINIA
2) Put user A’s profile in to cache (VIRGINIA) and return

3) Someone request User A’s profile image on SEOUL
4) Put user A’s profile in to cache (SEOUL) and return

5) User’A updates send profile image change request (VIRGINIA)
6) Update Database and purge cache (VIRGINIA)

7) Someone requests User A’s profile image from SEOUL
8) ???? Old Image ?????
Scenario
1) Someone request User A’s profile image from VIRGINIA
2) Put user A’s profile in to cache (VIRGINIA) and return

3) Someone request User A’s profile image on SEOUL
4) Put user A’s profile in to cache (SEOUL) and return

5) User’A updates send profile image change request (VIRGINIA)
6) Update Database and purge cache (VIRGINIA)
7) VIRGINA -> SEOUL, “DEL User’A Profile Image Cache” 

or, “SET User’A Profile Image Cache with new image”
8) Someone requests User A’s profile image from SEOUL
9) NEW IMAGE!
Challenge:
“How can we propagate 

cache change (DEL, SET) 

across regions?”
Available Solutions
Cross Region
Sync
Cache “GET”
Latency
Cost
DynamoDB 

(GlobalTable or
DynamDB Stream)
AWS Supported,
Non-Atomic

At least 1000ms
20~30ms
Auto-Scaled,
Pay-As-You-Go
AWS RDS + DMS
AWS Supported,
Non-Atomic

At least 1000ms
5~10ms
On-Promise,

Instance Based,
Expensive
Memcached No 1~5ms
On-Promise,

Instance Based,
Cheap
Redis No 1~5ms
On-Promise,

Instance Based,
Cheap
Netflix does it (Obviously)
Netflix does it, BUT
Requires,
1) Kafka Cluster
2) Service Discovery 

- Address of kafka in local region

- Address of Replication Proxy on
Other Region(S)
3) EVCache cluster
4) Monitoring, Logging.....
EVCache
- Basically, <Memcached + Extra Features>
- Extra Features
- Replication Layer (Capture every commands)
- Secondary Index (Using ElasticSearch)
- But AWS doesn't have "Managed EVCache"
So how can we do this in
"Severless" way?
CDN
AP-NORTHEAST-2
User
US-EAST-1
CDN
Edge (Lambda)
Edge (Lambda)
Memcached
Memcached
Replicator
Replicator
Firehose
S3 Bucket
Replicator (Lambda)
• It only knows "Local Region"
memcached url
• Receive SET / DEL command,
execute it
• Application should know all
other regions Replicators
endpoint
MemcachedReplicator Application
MemcachedReplicator Application
MemcachedReplicator Application
Replicator (Lambda)
export interface CacheEvent {
source: {
region: "us-east-1" | "ap-northeast-2";
};
metadata?: {
service: string; // Which service?
operation: string; // Which operation?
};
createdAt: number;
action: (

{
type: "SET";
key: string;
value: string;
lifetime: number;
} | {
type: "DEL";
key: string;
}
)
}
const memcached = new Memcached(process.env.URL);
export async function applyEvents(
events: CacheEvent[]
) {
await Promise.all(events.map(async (event) => {
const action = event.action;
switch (action.type) {
case "SET": {
return await memcached.set(

action.key, action.value, action.lifetime
);
}
case "DEL": {
return await memcached.del(action.key);
}
}
}));
}
Q. Application should know 

all other regions Replicators endpoint.
A. It's Lambda! ARN is pretty same. 

You don't need Service Discovery
npm run deploy:prod -- --region=ap-northeast-2
arn:aws:lambda:ap-northeast-2:12345:function:retriever-prod-receiver
npm run deploy:prod -- --region=us-east-1
arn:aws:lambda:us-east-1:12345:function:retriever-prod-receiver
npm run deploy:prod -- --region=us-west-1
arn:aws:lambda:us-west-1:12345:function:retriever-prod-receiver
Thus, At Application (Memcached Client),
const clients = [
"us-east-1",
"ap-west-1",
"ap-northeast-2"
].map(region => new AWS.Lambda({ region }));
async function set(key: string, value: string) {
const local = new MemcachedDriver(process.env.CACHE_URL);
await Promise.all([
local.set(key, value),
...clients.filter(c => c.region !== process.env.AWS_REGION).map((client) =>
client.invokeAsync({
FunctionName: "retriever-prod",
InvokeArgs: JSON.stringify({
source: process.env.AWS_REGION,
action: {
type: "SET", key, value
}
})
}).promise()
)
]);
}
Logging can be really complicated
1) For logging, it's better to have centralized bucket on single region
2) Otherwise, 

us-east-1 → ap-northeast-2 log is at ap-northeast-2

ap-northeast-2 → us-east-1 log is at us-east-1

3) memcached SET / DEL takes about 5~10ms
4) but cross region access (either KinesisFirehose or Cloudwatch) 

takes at least 300ms
5) So, Waiting for Logging is Really Really inefficient
6) And even expensive if you use Lambda. Cost = Duration * Memory
The only way to log without extra
latency in lambda:



Console.log + Cloudwatch
Replicator (Lambda)
const memcached = new Memcached(process.env.URL);
export async function applyEvents(
events: CacheEvent[]
) {
await Promise.all(events.map(async (event) => {
console.log(JSON.stringify(event));
const action = event.action;
switch (action.type) {
case "SET": {
return await memcached.set(

action.key, action.value, action.lifetime
);
}
case "DEL": {
return await memcached.del(action.key);
}
}
}));
}
But how can we "Query" or "Search" that?
- Cloudwatch → ElasticSearch,
- Work fine, A lot of guides, not serverless, Expensive
- Cloudwatch → Kinesis Firehose → S3 → Athena,
- SERVERLESS!
- Link
1) Gunzip Cloudwatch log data,
2) Format, remove invalid data,
3) return!
Athena
CREATE EXTERNAL TABLE `prod_events`(
`source` struct<region:string>,
`target` struct<region:string>,
`action` struct<
type:string,
key:string,
value:string,
lifetime:int
>
)
ROW FORMAT SERDE
'org.openx.data.jsonserde.JsonSerDe'
STORED AS INPUTFORMAT
'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
's3://retriever-prod-log/events'
Athena
QnA

More Related Content

What's hot

Kubernetes the Very Hard Way. Velocity Berlin 2019
Kubernetes the Very Hard Way. Velocity Berlin 2019Kubernetes the Very Hard Way. Velocity Berlin 2019
Kubernetes the Very Hard Way. Velocity Berlin 2019Laurent Bernaille
 
S3, Cassandra or Outer Space? Dumping Time Series Data using Spark - Demi Ben...
S3, Cassandra or Outer Space? Dumping Time Series Data using Spark - Demi Ben...S3, Cassandra or Outer Space? Dumping Time Series Data using Spark - Demi Ben...
S3, Cassandra or Outer Space? Dumping Time Series Data using Spark - Demi Ben...Codemotion Tel Aviv
 
Code for the earth OCP APAC Tokyo 2013-05
Code for the earth OCP APAC Tokyo 2013-05Code for the earth OCP APAC Tokyo 2013-05
Code for the earth OCP APAC Tokyo 2013-05Tetsu Saburi
 
Managing Container Clusters in OpenStack Native Way
Managing Container Clusters in OpenStack Native WayManaging Container Clusters in OpenStack Native Way
Managing Container Clusters in OpenStack Native WayQiming Teng
 
Kubernetes on AWS
Kubernetes on AWSKubernetes on AWS
Kubernetes on AWSGrant Ellis
 
Heat and its resources
Heat and its resourcesHeat and its resources
Heat and its resourcesSangeeth Kumar
 
Dbs302 driving a realtime personalization engine with cloud bigtable
Dbs302  driving a realtime personalization engine with cloud bigtableDbs302  driving a realtime personalization engine with cloud bigtable
Dbs302 driving a realtime personalization engine with cloud bigtableCalvin French-Owen
 
Deploy an Elastic, Resilient, Load-Balanced Cluster in 5 Minutes with Senlin
Deploy an Elastic, Resilient, Load-Balanced Cluster in 5 Minutes with SenlinDeploy an Elastic, Resilient, Load-Balanced Cluster in 5 Minutes with Senlin
Deploy an Elastic, Resilient, Load-Balanced Cluster in 5 Minutes with SenlinQiming Teng
 
Container Orchestration with Amazon ECS
Container Orchestration with Amazon ECSContainer Orchestration with Amazon ECS
Container Orchestration with Amazon ECSAmazon Web Services
 
Developing Scylla Applications: Practical Tips
Developing Scylla Applications: Practical TipsDeveloping Scylla Applications: Practical Tips
Developing Scylla Applications: Practical TipsScyllaDB
 
Kubernetes on Bare Metal at the Kitchener-Waterloo Kubernetes and Cloud Nativ...
Kubernetes on Bare Metal at the Kitchener-Waterloo Kubernetes and Cloud Nativ...Kubernetes on Bare Metal at the Kitchener-Waterloo Kubernetes and Cloud Nativ...
Kubernetes on Bare Metal at the Kitchener-Waterloo Kubernetes and Cloud Nativ...CloudOps2005
 
Autoscaling Kubernetes
Autoscaling KubernetesAutoscaling Kubernetes
Autoscaling Kubernetescraigbox
 
#NetflixEverywhere Global Architecture
#NetflixEverywhere Global Architecture#NetflixEverywhere Global Architecture
#NetflixEverywhere Global ArchitectureC4Media
 
(ARC348) Seagull: How Yelp Built A System For Task Execution
(ARC348) Seagull: How Yelp Built A System For Task Execution(ARC348) Seagull: How Yelp Built A System For Task Execution
(ARC348) Seagull: How Yelp Built A System For Task ExecutionAmazon Web Services
 
Microservices blue-green-deployment-with-docker
Microservices blue-green-deployment-with-dockerMicroservices blue-green-deployment-with-docker
Microservices blue-green-deployment-with-dockerKidong Lee
 
Exploring Magnum and Senlin integration for autoscaling containers
Exploring Magnum and Senlin integration for autoscaling containersExploring Magnum and Senlin integration for autoscaling containers
Exploring Magnum and Senlin integration for autoscaling containersTon Ngo
 
Kubernetes Walk Through from Technical View
Kubernetes Walk Through from Technical ViewKubernetes Walk Through from Technical View
Kubernetes Walk Through from Technical ViewLei (Harry) Zhang
 
AWS migration: getting to Data Center heaven with AWS and Chef
AWS migration: getting to Data Center heaven with AWS and ChefAWS migration: getting to Data Center heaven with AWS and Chef
AWS migration: getting to Data Center heaven with AWS and ChefJuan Vicente Herrera Ruiz de Alejo
 
Kubernetes Services are sooo Yesterday!
Kubernetes Services are sooo Yesterday!Kubernetes Services are sooo Yesterday!
Kubernetes Services are sooo Yesterday!CloudOps2005
 
Terraform Abstractions for Safety and Power
Terraform Abstractions for Safety and PowerTerraform Abstractions for Safety and Power
Terraform Abstractions for Safety and PowerCalvin French-Owen
 

What's hot (20)

Kubernetes the Very Hard Way. Velocity Berlin 2019
Kubernetes the Very Hard Way. Velocity Berlin 2019Kubernetes the Very Hard Way. Velocity Berlin 2019
Kubernetes the Very Hard Way. Velocity Berlin 2019
 
S3, Cassandra or Outer Space? Dumping Time Series Data using Spark - Demi Ben...
S3, Cassandra or Outer Space? Dumping Time Series Data using Spark - Demi Ben...S3, Cassandra or Outer Space? Dumping Time Series Data using Spark - Demi Ben...
S3, Cassandra or Outer Space? Dumping Time Series Data using Spark - Demi Ben...
 
Code for the earth OCP APAC Tokyo 2013-05
Code for the earth OCP APAC Tokyo 2013-05Code for the earth OCP APAC Tokyo 2013-05
Code for the earth OCP APAC Tokyo 2013-05
 
Managing Container Clusters in OpenStack Native Way
Managing Container Clusters in OpenStack Native WayManaging Container Clusters in OpenStack Native Way
Managing Container Clusters in OpenStack Native Way
 
Kubernetes on AWS
Kubernetes on AWSKubernetes on AWS
Kubernetes on AWS
 
Heat and its resources
Heat and its resourcesHeat and its resources
Heat and its resources
 
Dbs302 driving a realtime personalization engine with cloud bigtable
Dbs302  driving a realtime personalization engine with cloud bigtableDbs302  driving a realtime personalization engine with cloud bigtable
Dbs302 driving a realtime personalization engine with cloud bigtable
 
Deploy an Elastic, Resilient, Load-Balanced Cluster in 5 Minutes with Senlin
Deploy an Elastic, Resilient, Load-Balanced Cluster in 5 Minutes with SenlinDeploy an Elastic, Resilient, Load-Balanced Cluster in 5 Minutes with Senlin
Deploy an Elastic, Resilient, Load-Balanced Cluster in 5 Minutes with Senlin
 
Container Orchestration with Amazon ECS
Container Orchestration with Amazon ECSContainer Orchestration with Amazon ECS
Container Orchestration with Amazon ECS
 
Developing Scylla Applications: Practical Tips
Developing Scylla Applications: Practical TipsDeveloping Scylla Applications: Practical Tips
Developing Scylla Applications: Practical Tips
 
Kubernetes on Bare Metal at the Kitchener-Waterloo Kubernetes and Cloud Nativ...
Kubernetes on Bare Metal at the Kitchener-Waterloo Kubernetes and Cloud Nativ...Kubernetes on Bare Metal at the Kitchener-Waterloo Kubernetes and Cloud Nativ...
Kubernetes on Bare Metal at the Kitchener-Waterloo Kubernetes and Cloud Nativ...
 
Autoscaling Kubernetes
Autoscaling KubernetesAutoscaling Kubernetes
Autoscaling Kubernetes
 
#NetflixEverywhere Global Architecture
#NetflixEverywhere Global Architecture#NetflixEverywhere Global Architecture
#NetflixEverywhere Global Architecture
 
(ARC348) Seagull: How Yelp Built A System For Task Execution
(ARC348) Seagull: How Yelp Built A System For Task Execution(ARC348) Seagull: How Yelp Built A System For Task Execution
(ARC348) Seagull: How Yelp Built A System For Task Execution
 
Microservices blue-green-deployment-with-docker
Microservices blue-green-deployment-with-dockerMicroservices blue-green-deployment-with-docker
Microservices blue-green-deployment-with-docker
 
Exploring Magnum and Senlin integration for autoscaling containers
Exploring Magnum and Senlin integration for autoscaling containersExploring Magnum and Senlin integration for autoscaling containers
Exploring Magnum and Senlin integration for autoscaling containers
 
Kubernetes Walk Through from Technical View
Kubernetes Walk Through from Technical ViewKubernetes Walk Through from Technical View
Kubernetes Walk Through from Technical View
 
AWS migration: getting to Data Center heaven with AWS and Chef
AWS migration: getting to Data Center heaven with AWS and ChefAWS migration: getting to Data Center heaven with AWS and Chef
AWS migration: getting to Data Center heaven with AWS and Chef
 
Kubernetes Services are sooo Yesterday!
Kubernetes Services are sooo Yesterday!Kubernetes Services are sooo Yesterday!
Kubernetes Services are sooo Yesterday!
 
Terraform Abstractions for Safety and Power
Terraform Abstractions for Safety and PowerTerraform Abstractions for Safety and Power
Terraform Abstractions for Safety and Power
 

Similar to Serverless Multi Region Cache Replication

Deploying your web application with AWS ElasticBeanstalk
Deploying your web application with AWS ElasticBeanstalkDeploying your web application with AWS ElasticBeanstalk
Deploying your web application with AWS ElasticBeanstalkJulien SIMON
 
Advanced Task Scheduling with Amazon ECS (June 2017)
Advanced Task Scheduling with Amazon ECS (June 2017)Advanced Task Scheduling with Amazon ECS (June 2017)
Advanced Task Scheduling with Amazon ECS (June 2017)Julien SIMON
 
CloudFork
CloudForkCloudFork
CloudForkESUG
 
Cloud computing & lamp applications
Cloud computing & lamp applicationsCloud computing & lamp applications
Cloud computing & lamp applicationsCorley S.r.l.
 
Kubernetes Multitenancy Karl Isenberg - KubeCon NA 2019
Kubernetes Multitenancy   Karl Isenberg - KubeCon NA 2019Kubernetes Multitenancy   Karl Isenberg - KubeCon NA 2019
Kubernetes Multitenancy Karl Isenberg - KubeCon NA 2019Karl Isenberg
 
ILM - Pipeline in the cloud
ILM - Pipeline in the cloudILM - Pipeline in the cloud
ILM - Pipeline in the cloudAaron Carey
 
Disaster Recovery Site on AWS - Minimal Cost Maximum Efficiency (STG305) | AW...
Disaster Recovery Site on AWS - Minimal Cost Maximum Efficiency (STG305) | AW...Disaster Recovery Site on AWS - Minimal Cost Maximum Efficiency (STG305) | AW...
Disaster Recovery Site on AWS - Minimal Cost Maximum Efficiency (STG305) | AW...Amazon Web Services
 
Scalability strategies for cloud based system architecture
Scalability strategies for cloud based system architectureScalability strategies for cloud based system architecture
Scalability strategies for cloud based system architectureSangJin Kang
 
AWS Summit Berlin 2013 - Euroforum - Moving an Entire Physical Data Center in...
AWS Summit Berlin 2013 - Euroforum - Moving an Entire Physical Data Center in...AWS Summit Berlin 2013 - Euroforum - Moving an Entire Physical Data Center in...
AWS Summit Berlin 2013 - Euroforum - Moving an Entire Physical Data Center in...AWS Germany
 
Leveraging Amazon Web Services for Scalable Media Distribution and Analytics ...
Leveraging Amazon Web Services for Scalable Media Distribution and Analytics ...Leveraging Amazon Web Services for Scalable Media Distribution and Analytics ...
Leveraging Amazon Web Services for Scalable Media Distribution and Analytics ...Amazon Web Services
 
Jacopo Nardiello - Monitoring Cloud-Native applications with Prometheus - Cod...
Jacopo Nardiello - Monitoring Cloud-Native applications with Prometheus - Cod...Jacopo Nardiello - Monitoring Cloud-Native applications with Prometheus - Cod...
Jacopo Nardiello - Monitoring Cloud-Native applications with Prometheus - Cod...Codemotion
 
데이터 마이그레이션 AWS와 같이하기 - 김일호 솔루션즈 아키텍트:: AWS Cloud Track 3 Gaming
데이터 마이그레이션 AWS와 같이하기 - 김일호 솔루션즈 아키텍트:: AWS Cloud Track 3 Gaming데이터 마이그레이션 AWS와 같이하기 - 김일호 솔루션즈 아키텍트:: AWS Cloud Track 3 Gaming
데이터 마이그레이션 AWS와 같이하기 - 김일호 솔루션즈 아키텍트:: AWS Cloud Track 3 GamingAmazon Web Services Korea
 
Building services on AWS in China region
Building services on AWS in China regionBuilding services on AWS in China region
Building services on AWS in China regionRoman Naumenko
 
StrongLoop Overview
StrongLoop OverviewStrongLoop Overview
StrongLoop OverviewShubhra Kar
 
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...Amazon Web Services
 
Introducing envoy-based service mesh at Booking.com
Introducing envoy-based service mesh at Booking.comIntroducing envoy-based service mesh at Booking.com
Introducing envoy-based service mesh at Booking.comIvan Kruglov
 
Encode x NEAR: Technical Overview of NEAR 1
Encode x NEAR: Technical Overview of NEAR 1Encode x NEAR: Technical Overview of NEAR 1
Encode x NEAR: Technical Overview of NEAR 1KlaraOrban
 
GumGum: Multi-Region Cassandra in AWS
GumGum: Multi-Region Cassandra in AWSGumGum: Multi-Region Cassandra in AWS
GumGum: Multi-Region Cassandra in AWSDataStax Academy
 
Cutting through the fog of cloud
Cutting through the fog of cloudCutting through the fog of cloud
Cutting through the fog of cloudKyle Rames
 
Cloud-native applications with Java and Kubernetes - Yehor Volkov
 Cloud-native applications with Java and Kubernetes - Yehor Volkov Cloud-native applications with Java and Kubernetes - Yehor Volkov
Cloud-native applications with Java and Kubernetes - Yehor VolkovKuberton
 

Similar to Serverless Multi Region Cache Replication (20)

Deploying your web application with AWS ElasticBeanstalk
Deploying your web application with AWS ElasticBeanstalkDeploying your web application with AWS ElasticBeanstalk
Deploying your web application with AWS ElasticBeanstalk
 
Advanced Task Scheduling with Amazon ECS (June 2017)
Advanced Task Scheduling with Amazon ECS (June 2017)Advanced Task Scheduling with Amazon ECS (June 2017)
Advanced Task Scheduling with Amazon ECS (June 2017)
 
CloudFork
CloudForkCloudFork
CloudFork
 
Cloud computing & lamp applications
Cloud computing & lamp applicationsCloud computing & lamp applications
Cloud computing & lamp applications
 
Kubernetes Multitenancy Karl Isenberg - KubeCon NA 2019
Kubernetes Multitenancy   Karl Isenberg - KubeCon NA 2019Kubernetes Multitenancy   Karl Isenberg - KubeCon NA 2019
Kubernetes Multitenancy Karl Isenberg - KubeCon NA 2019
 
ILM - Pipeline in the cloud
ILM - Pipeline in the cloudILM - Pipeline in the cloud
ILM - Pipeline in the cloud
 
Disaster Recovery Site on AWS - Minimal Cost Maximum Efficiency (STG305) | AW...
Disaster Recovery Site on AWS - Minimal Cost Maximum Efficiency (STG305) | AW...Disaster Recovery Site on AWS - Minimal Cost Maximum Efficiency (STG305) | AW...
Disaster Recovery Site on AWS - Minimal Cost Maximum Efficiency (STG305) | AW...
 
Scalability strategies for cloud based system architecture
Scalability strategies for cloud based system architectureScalability strategies for cloud based system architecture
Scalability strategies for cloud based system architecture
 
AWS Summit Berlin 2013 - Euroforum - Moving an Entire Physical Data Center in...
AWS Summit Berlin 2013 - Euroforum - Moving an Entire Physical Data Center in...AWS Summit Berlin 2013 - Euroforum - Moving an Entire Physical Data Center in...
AWS Summit Berlin 2013 - Euroforum - Moving an Entire Physical Data Center in...
 
Leveraging Amazon Web Services for Scalable Media Distribution and Analytics ...
Leveraging Amazon Web Services for Scalable Media Distribution and Analytics ...Leveraging Amazon Web Services for Scalable Media Distribution and Analytics ...
Leveraging Amazon Web Services for Scalable Media Distribution and Analytics ...
 
Jacopo Nardiello - Monitoring Cloud-Native applications with Prometheus - Cod...
Jacopo Nardiello - Monitoring Cloud-Native applications with Prometheus - Cod...Jacopo Nardiello - Monitoring Cloud-Native applications with Prometheus - Cod...
Jacopo Nardiello - Monitoring Cloud-Native applications with Prometheus - Cod...
 
데이터 마이그레이션 AWS와 같이하기 - 김일호 솔루션즈 아키텍트:: AWS Cloud Track 3 Gaming
데이터 마이그레이션 AWS와 같이하기 - 김일호 솔루션즈 아키텍트:: AWS Cloud Track 3 Gaming데이터 마이그레이션 AWS와 같이하기 - 김일호 솔루션즈 아키텍트:: AWS Cloud Track 3 Gaming
데이터 마이그레이션 AWS와 같이하기 - 김일호 솔루션즈 아키텍트:: AWS Cloud Track 3 Gaming
 
Building services on AWS in China region
Building services on AWS in China regionBuilding services on AWS in China region
Building services on AWS in China region
 
StrongLoop Overview
StrongLoop OverviewStrongLoop Overview
StrongLoop Overview
 
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...
(ARC402) Deployment Automation: From Developers' Keyboards to End Users' Scre...
 
Introducing envoy-based service mesh at Booking.com
Introducing envoy-based service mesh at Booking.comIntroducing envoy-based service mesh at Booking.com
Introducing envoy-based service mesh at Booking.com
 
Encode x NEAR: Technical Overview of NEAR 1
Encode x NEAR: Technical Overview of NEAR 1Encode x NEAR: Technical Overview of NEAR 1
Encode x NEAR: Technical Overview of NEAR 1
 
GumGum: Multi-Region Cassandra in AWS
GumGum: Multi-Region Cassandra in AWSGumGum: Multi-Region Cassandra in AWS
GumGum: Multi-Region Cassandra in AWS
 
Cutting through the fog of cloud
Cutting through the fog of cloudCutting through the fog of cloud
Cutting through the fog of cloud
 
Cloud-native applications with Java and Kubernetes - Yehor Volkov
 Cloud-native applications with Java and Kubernetes - Yehor Volkov Cloud-native applications with Java and Kubernetes - Yehor Volkov
Cloud-native applications with Java and Kubernetes - Yehor Volkov
 

Recently uploaded

Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 

Recently uploaded (20)

Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 

Serverless Multi Region Cache Replication

  • 2. Kurt Lee Technical Leader, Vingle Inc iOS / Frontend / Backend kurt@vingle.net https://github.com/breath103
  • 3. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved. Vingle, Interest Network
  • 4. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
  • 5. Q. What’s the point of doing multi region without local cache
  • 6. Things That Will Not Be Covered a. Why Master-Master Multi Region is SO HARD b. How to migrate Monolith to Microservice c. How to migrate to Serverless (Lambda)
  • 7. Things That Will Be Covered a. How to build multi-region cache replication b. Include monitoring / backup c. in Serverless
  • 8. CDN AP-NORTHEAST-2 User US-EAST-1 CDN Edge (Lambda) Edge (Lambda) Memcached Memcached Feed User Card
  • 9. Scenario 1) Someone request User A’s profile image from VIRGINIA 2) Put user A’s profile in to cache (VIRGINIA) and return
 3) Someone request User A’s profile image on SEOUL 4) Put user A’s profile in to cache (SEOUL) and return
 5) User’A updates send profile image change request (VIRGINIA) 6) Update Database and purge cache (VIRGINIA)
 7) Someone requests User A’s profile image from SEOUL 8) ???? Old Image ?????
  • 10. Scenario 1) Someone request User A’s profile image from VIRGINIA 2) Put user A’s profile in to cache (VIRGINIA) and return
 3) Someone request User A’s profile image on SEOUL 4) Put user A’s profile in to cache (SEOUL) and return
 5) User’A updates send profile image change request (VIRGINIA) 6) Update Database and purge cache (VIRGINIA) 7) VIRGINA -> SEOUL, “DEL User’A Profile Image Cache” 
 or, “SET User’A Profile Image Cache with new image” 8) Someone requests User A’s profile image from SEOUL 9) NEW IMAGE!
  • 11. Challenge: “How can we propagate 
 cache change (DEL, SET) 
 across regions?”
  • 12. Available Solutions Cross Region Sync Cache “GET” Latency Cost DynamoDB 
 (GlobalTable or DynamDB Stream) AWS Supported, Non-Atomic
 At least 1000ms 20~30ms Auto-Scaled, Pay-As-You-Go AWS RDS + DMS AWS Supported, Non-Atomic
 At least 1000ms 5~10ms On-Promise,
 Instance Based, Expensive Memcached No 1~5ms On-Promise,
 Instance Based, Cheap Redis No 1~5ms On-Promise,
 Instance Based, Cheap
  • 13. Netflix does it (Obviously)
  • 14. Netflix does it, BUT Requires, 1) Kafka Cluster 2) Service Discovery 
 - Address of kafka in local region
 - Address of Replication Proxy on Other Region(S) 3) EVCache cluster 4) Monitoring, Logging.....
  • 15. EVCache - Basically, <Memcached + Extra Features> - Extra Features - Replication Layer (Capture every commands) - Secondary Index (Using ElasticSearch) - But AWS doesn't have "Managed EVCache"
  • 16. So how can we do this in "Severless" way?
  • 18. Replicator (Lambda) • It only knows "Local Region" memcached url • Receive SET / DEL command, execute it • Application should know all other regions Replicators endpoint MemcachedReplicator Application MemcachedReplicator Application MemcachedReplicator Application
  • 19. Replicator (Lambda) export interface CacheEvent { source: { region: "us-east-1" | "ap-northeast-2"; }; metadata?: { service: string; // Which service? operation: string; // Which operation? }; createdAt: number; action: (
 { type: "SET"; key: string; value: string; lifetime: number; } | { type: "DEL"; key: string; } ) } const memcached = new Memcached(process.env.URL); export async function applyEvents( events: CacheEvent[] ) { await Promise.all(events.map(async (event) => { const action = event.action; switch (action.type) { case "SET": { return await memcached.set(
 action.key, action.value, action.lifetime ); } case "DEL": { return await memcached.del(action.key); } } })); }
  • 20. Q. Application should know 
 all other regions Replicators endpoint. A. It's Lambda! ARN is pretty same. 
 You don't need Service Discovery npm run deploy:prod -- --region=ap-northeast-2 arn:aws:lambda:ap-northeast-2:12345:function:retriever-prod-receiver npm run deploy:prod -- --region=us-east-1 arn:aws:lambda:us-east-1:12345:function:retriever-prod-receiver npm run deploy:prod -- --region=us-west-1 arn:aws:lambda:us-west-1:12345:function:retriever-prod-receiver
  • 21. Thus, At Application (Memcached Client), const clients = [ "us-east-1", "ap-west-1", "ap-northeast-2" ].map(region => new AWS.Lambda({ region })); async function set(key: string, value: string) { const local = new MemcachedDriver(process.env.CACHE_URL); await Promise.all([ local.set(key, value), ...clients.filter(c => c.region !== process.env.AWS_REGION).map((client) => client.invokeAsync({ FunctionName: "retriever-prod", InvokeArgs: JSON.stringify({ source: process.env.AWS_REGION, action: { type: "SET", key, value } }) }).promise() ) ]); }
  • 22. Logging can be really complicated 1) For logging, it's better to have centralized bucket on single region 2) Otherwise, 
 us-east-1 → ap-northeast-2 log is at ap-northeast-2
 ap-northeast-2 → us-east-1 log is at us-east-1
 3) memcached SET / DEL takes about 5~10ms 4) but cross region access (either KinesisFirehose or Cloudwatch) 
 takes at least 300ms 5) So, Waiting for Logging is Really Really inefficient 6) And even expensive if you use Lambda. Cost = Duration * Memory
  • 23. The only way to log without extra latency in lambda:
 
 Console.log + Cloudwatch
  • 24. Replicator (Lambda) const memcached = new Memcached(process.env.URL); export async function applyEvents( events: CacheEvent[] ) { await Promise.all(events.map(async (event) => { console.log(JSON.stringify(event)); const action = event.action; switch (action.type) { case "SET": { return await memcached.set(
 action.key, action.value, action.lifetime ); } case "DEL": { return await memcached.del(action.key); } } })); }
  • 25. But how can we "Query" or "Search" that? - Cloudwatch → ElasticSearch, - Work fine, A lot of guides, not serverless, Expensive - Cloudwatch → Kinesis Firehose → S3 → Athena, - SERVERLESS! - Link
  • 26. 1) Gunzip Cloudwatch log data, 2) Format, remove invalid data, 3) return!
  • 27. Athena CREATE EXTERNAL TABLE `prod_events`( `source` struct<region:string>, `target` struct<region:string>, `action` struct< type:string, key:string, value:string, lifetime:int > ) ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe' STORED AS INPUTFORMAT 'org.apache.hadoop.mapred.TextInputFormat' OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' LOCATION 's3://retriever-prod-log/events'
  • 29. QnA