Serverless Architecture Patterns - Manoj Ganapathi - Serverless Summit
SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have...
Transcript of SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have...
![Page 1: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/1.jpg)
SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS
Donna Malayeri
Product Manager, Pulumi
@PulumiCorp@lindydonna
![Page 2: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/2.jpg)
![Page 3: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/3.jpg)
@lindydonna
SERVERLESS AND CONTAINERS
• Tradeoff between control and productivity
• Containers give you full control over your compute workloads
• Serverless scales instantly and is cheaper to own and operate
• Modern applications need both compute models
![Page 4: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/4.jpg)
@lindydonna
PROGRAMMING IS ABOUT ABSTRACTION
• JavaScript• Go• Python• Ruby
• C#• Java• C/C++
• Assembly
If I have seen further it is only by standing on the shoulders of giants.
-- Isaac Newton
![Page 5: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/5.jpg)
Control
Abstraction
Virtual Machines
Containers
Serverless Containers
Platform as a Service
Serverless
The cloud landscape
![Page 6: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/6.jpg)
@lindydonna
• How often should I patch my server?
• How do I patch?
• How do I deploy code?
• How many servers do I need?
• How can I scale my app?
IN THE EARLY DAYS OF CLOUD, THERE WERE ONLY VIRTUAL MACHINES
![Page 7: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/7.jpg)
@lindydonna
CONTAINERS REDUCE COMPLEXITY
DockerfileDocker image
Container orchestrator
![Page 8: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/8.jpg)
CONTAINERS
DockerfileDocker image Container registry
docker build
AWS Elastic Container Service
Task definition
Service description
![Page 9: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/9.jpg)
@lindydonna
CONTAINER BENEFITS
• Abstraction for compute: containers instead of VMs
• Useful package format
• Full control over application environment
• Full control over task placement
• Control over compute resources
![Page 10: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/10.jpg)
CONTAINERS AT RUNTIME
ECS Service Description
Task definition
Service description
Graphic: https://medium.freecodecamp.org/amazon-ecs-terms-and-architecture-807d8c4960fd
![Page 11: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/11.jpg)
@lindydonna
CONTAINERS: THINGS TO MANAGE
• How often should I update my Dockerfile dependencies?
• How do I build my container images?
• How do I get my containers in production?
• How many servers do I need?
• How can I scale my app?
![Page 12: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/12.jpg)
SERVERLESS: JUST PROVIDE YOUR CODE
Code zipfile
Cloud icons: https://www.flaticon.com/authors/payungkead
Cloud platform
Trigger definition
![Page 13: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/13.jpg)
SERVERLESS
• Event-driven compute with near-instant scale
• Managed, ephemeral compute
• Never pay for idle
(Btw, there are actually servers)
AWS Lambda
Google Cloud Functions
Azure Functions
![Page 14: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/14.jpg)
@lindydonna
WHY SERVERLESS?
• Reduce operational overhead
• Faster time to market
• Focus on business value
The Serverless Spectrum https://read.acloud.guru/the-serverless-spectrum-147b02cb2292
![Page 15: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/15.jpg)
SCHEDULED TASKS
https://functions.azure.com
![Page 16: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/16.jpg)
CREATE IMAGE THUMBNAIL
https://aws.amazon.com/lambda/
![Page 17: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/17.jpg)
ANALYZE SOCIAL MEDIA STREAM
https://aws.amazon.com/lambda/
![Page 18: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/18.jpg)
@lindydonna
SERVERLESS CAVEATS
• Works best for event-based workloads
• Cloud vendor supports specific languages and runtimes
• Can’t customize execution environment
• Not well-suited for long-running tasks
![Page 19: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/19.jpg)
ANALOGY: RENTING VS OWNING A BIKE
![Page 20: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/20.jpg)
@lindydonna
NEW CONTAINER EXECUTION MODELS
• Azure Container Instances
• AWS Fargate
• On-demand containers
• Don’t have to manage underlying cluster
![Page 21: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/21.jpg)
@lindydonna
CONTAINERS AND SERVERLESS
• Use containers for control over the execution environment
• Customize software and physical servers
• Great for long-running compute
• Use serverless for event-based compute that scales on demand
• Less to manage
• Less to configure
![Page 22: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/22.jpg)
Control
Abstraction
Virtual Machines
Containers
Serverless Containers
Platform as a Service
Serverless
The cloud landscape
![Page 23: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/23.jpg)
COMBINING THE TWO
![Page 24: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/24.jpg)
EXAMPLE: VIDEO THUMBNAILER
Bucket
onNewVideo
Lambda
New .mp4 file Launch task Write .jpg
BucketECS Fargate Task
ffmpegTask
New .jpg file
onNewThumbnail
Lambda
![Page 25: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/25.jpg)
EXAMPLE: RAY TRACING
scene.zip
ECS Cluster
![Page 26: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/26.jpg)
EXAMPLE: CONTENT MODERATION
Image
![Page 27: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/27.jpg)
EXAMPLE: FUNCTION CHAINING
const df = require("durable-functions");
module.exports = df(function*(ctx) {const x = yield ctx.df.callActivityAsync("F1");const y = yield ctx.df.callActivityAsync("F2", x);const z = yield ctx.df.callActivityAsync("F3", y);return yield ctx.df.callActivityAsync("F4", z);
});
![Page 28: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/28.jpg)
EXAMPLE: DURABLE FUNCTIONS
![Page 29: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/29.jpg)
TOOLS
![Page 30: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/30.jpg)
VENDOR DEPLOYMENT TOOLS
AWS CLOUDFORMATION AZURE RESOURCE MANAGER GOOGLE CLOUD DEPLOYMENT MANAGER
![Page 31: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/31.jpg)
@lindydonna
TOOLS ALSO PROVIDE ABSTRACTION
• Use Terraform modules
• Use Serverless Framework plugins or components
• Use Pulumi components
• Examples: github.com/lindydonna/velocity-examples
![Page 32: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/32.jpg)
Control
Abstraction
Virtual Machines
Containers
Serverless Containers
Platform as a Service
Serverless
The cloud landscape
![Page 33: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/33.jpg)
CONTAINERS
DockerfileDocker image Container registry
docker build
AWS Elastic Container Service
Task definition
Service description
![Page 34: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/34.jpg)
EXAMPLE: VIDEO THUMBNAILER
Bucket
onNewVideo
Lambda
New .mp4 file Launch task Write .jpg
BucketECS Fargate Task
ffmpegTask
New .jpg file
onNewThumbnail
Lambda
![Page 35: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/35.jpg)
DEFINING THE APP IN PULUMI
DockerfileonNewVideo onNewThumbnailffmpegTaskFROM jrottenberg/ffmpeg
RUN apt-get update && \apt-get install python-dev python-pip -y && \apt-get clean
RUN pip install awscli
WORKDIR /tmp/workdir
ENTRYPOINT \aws s3 cp s3://${S3_BUCKET}/${INPUT_VIDEO} ./${INPUT_VIDEO} && \ffmpeg -i ./${INPUT_VIDEO} -ss ${TIME_OFFSET} -vframes 1 -f image2 -an -y ${OUTPUT_FILE} && \aws s3 cp ./${OUTPUT_FILE} s3://${S3_BUCKET}/${OUTPUT_FILE}
![Page 36: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/36.jpg)
let bucket = new cloud.Bucket("bucket");
bucket.onPut("onNewThumbnail", async (bucketArgs) => {console.log(`*** New thumbnail: file ${bucketArgs.key}.`);
}, { keySuffix: ".jpg" });
let ffmpegTask = new cloud.Task("ffmpegTask", {build: "./docker-folder",memoryReservation: 512,
});
bucket.onPut("onNewVideo", async (bucketArgs) => {const file = bucketArgs.key;const framePos = ... // extract timestamp from filename
await ffmpegTask.run({environment: {"S3_BUCKET": bucket.id.get(),"INPUT_VIDEO": file,"TIME_OFFSET": framePos,"OUTPUT_FILE": file + '.jpg',
},});
}, { keySuffix: ".mp4" });
ECS taskECR repository
ECS clusterContainer image
IAM roles
![Page 37: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/37.jpg)
EXAMPLE: PROVISION QUEUES
function createQueue(name, deadLetter) {
return new aws.sqs.Queue(`${common.prefix}-${name}`, { ... });
}
exports.certIssuer = {
request: createQueue("c-i-req”, true),
response: createQueue("c-i-res", true),
prepare: createQueue("c-i-prep", true),
initOrg: createQueue("c-i-init-org", true),
initOrgRes: createQueue("c-i-init-org-res", true),
confirmTxs: createQueue("confirm-tx"),
};
![Page 38: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/38.jpg)
Control
Abstraction
Virtual Machines
Containers
Serverless Containers
Platform as a Service
Serverless
The cloud landscape
![Page 39: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/39.jpg)
@lindydonna
CONTAINERS WITH PULUMI
• How often should I update my Dockerfile dependencies?
• How do I build my container images?
• How do I get my containers in production?
• How many servers do I need?
• How can I scale my app?
![Page 40: SERVERLESS + CONTAINERS = MODERN CLOUD APPLICATIONS · • Serverless and containers each have their place • Use serverless for event -based code that needs to scale on demand •](https://reader033.fdocuments.us/reader033/viewer/2022060209/5f046c0c7e708231d40de3bd/html5/thumbnails/40.jpg)
@lindydonna
SUMMARY
• Serverless and containers each have their place
• Use serverless for event-based code that needs to scale on demand
• Use containers for durable workloads, or to customize environment
• Define abstractions using infrastructure-as-code tooling
Learn more at pulumi.iogithub.com/pulumi
@PulumiCorp