2. This presentation has been prepared by EPAM Systems, Inc. solely for use by EPAM at its EPAM Zed
Conference. This presentation or the information contained herein may not be reproduced or used
for any other purpose. This presentation includes highly confidential and proprietary information and
is delivered on the express condition that such information will not be disclosed to anyone except
persons in the recipient organization who have a need to know solely for the purpose described
above. No copies of this presentation will be made, and no other distribution will be made, without
the consent of EPAM. Any distribution of this presentation to any other person, in whole or in part,
or the reproduction of this presentation, or the divulgence of any of its contents is unauthorized.
CONFIDENTIAL INFORMATION
6. Focus on business value, not infrastructure
1. F A S T E R T I M E T O M A R K E T
2.
3.
R E D U C E D C O S T S
I M P R O V E D R E L I A B I L I T Y
6
4. I N C R E A S E D R AT E O F I N N O VAT I O N
7. Faster time to market
By eliminating operational overhead, your teams can release quickly, get
feedback, and iterate to get to market faster.
8. Reduced costs
With a pay-for-value billing model, you never pay for over-provisioning and
your resource utilization is optimized on your behalf.
10. Increased rate of innovation
Serverless applications have built-in service integrations, so you can focus on
building your application instead of configuring it.
12. AWS Lambda/Serverless patterns overview
AWS designed many solutions, and you should just find building
blocks for your cases
• Web application
• Mobile application for social distancing
• Mobile back-end
• Real-time stream processing
• IoT back-end
• AWS Connected mobility architecture
• Real-time file processing
• MapReduce
• Image recognition & processing
• Image moderator chatbot
12
https://aws.amazon.com/lambda/resources/reference-architectures/
17. Myths
Myth #1: Serverless means “no server and hardware”
• You need to setup required RAM size
Myth #2: Serverless == Lambda (AWS Lambda, Azure Functions etc.)
• Amazon enumerates as serverless such services as S3, SQS, SNS, API Gateway, DynamoDB
Myth #3: Serverless is cheap, definitely cheaper than “serverfull” solution
• Not always, you always should calculate costs ahead to see if it’s good fit
18. Going Stateful Anti-Pattern
Antipattern #1: Going stateful (in-memory state)
Problem
• Though lambda instance can be preserved for the next requests (such called
“hot start”), it is not guaranteed
• After lambda run, lambda instance can be terminated anytime
Solution
• You need a state, store it in external services
18
19. Do Not Pay Attention To Service Specifics
Antipattern #2: Do not pay attention to service specifics
Problem
• “I just write my code and deploy it to AWS Lambda – and everything works” – right, but only if
you agree with terms of service. AWS Lambda for example, have number of limitations (quotas):
• Request size <= 6Mb (so you cannot use it for file upload, use S3 for that)
• Max execution time is 15 minutes (lambda is terminated by timeout then)
Solution
• Regularly revisit quotas, know your data, check if they fit
• Remember there are hard and soft limits, soft limits can be increased on request
19
20. My Favorite Stack Is Great At Lambdas
Antipattern #3: Use your favorite tech stack without paying attention at cost
Problem
• Startup can be much slower in comparison to using plain old java or another language
• You are charged on a second basis.
Reducing overall duration from 10 seconds to 5 seconds will cut your costs twice
• Decreasing memory size (because code in Java was rewritten in Go) by two times will cut your costs
twice
Solution
• As lambda should be small, you can write it in Go/Python/JavaScript even if you are not a Pro in this
language
• So the pattern is: consider if the cost benefit worth learning
20
21. Multithreading Is Great In Lambdas
Antipattern #4: Using old-fashioned way for orchestration
Problem
“I will save a record in DynamoDB from lambda
and then Thread.sleep for another service to update it’s status”
• Each second if lambda does not do anything, you still pay money
• Avoid explicit and try to avoid implicit waits
• Implicit wait – blocking lambda instance awaiting for response from synchronous calls (RESTs)
• Explicit wait – Thread.sleep, polling messages from queues in while loops, checking state in while loops
etc.
Solution
• Orchestration using AWS Step Functions
• Choreography using message brokers (SQS, EventBridge, Kinesis, DynamoDB Streams)
21
23. Serverless Application Model
• Build serverless applications in simple and clean syntax
• Features:
• Built on AWS CloudFormation
• Built-In Best Practices
• Single Deployment Configuration
• Local Testing and Debugging
(+ https://localstack.cloud/)
• Serverless Application Model - https://aws.amazon.com/serverless/sam/
25. Nested Stacks
• Nested stacks are stacks created as part of other stacks.
• Nested stacks can themselves contain other nested stacks, resulting in a
hierarchy of stacks, as in the diagram below. The root stack is the top-
level stack to which all the nested stacks ultimately belong. In addition,
each nested stack has an immediate parent stack. For the first level of
nested stacks, the root stack is also the parent stack. in the diagram
below, for example:
• Stack A is the root stack for all the other, nested, stacks in the hierarchy.
• For stack B, stack A is both the parent stack, and the root stack.
• For stack D, stack C is the parent stack; while for stack C, stack B is the
parent stack.
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-
cfn-nested-stacks.html
26. Know Your Limits
• Lambda’s executions
• Concurrent executions - 1,000
• Step Functions
• Maximum number of registered state machines - 10,000
• Maximum open executions per account - 1,000,000 executions
per AWS account.
• ENIs for Lambdas are not endless
• Elastic network interfaces per virtual private cloud (VPC) - 250
• Limit on S3 buckets for Lambdas
• Buckets - 100 per account
27. AWS Lambda Power Tuning
AWS Lambda Power Tuning is a state machine powered by AWS Step Functions that helps you optimize your Lambda functions for cost
and/or performance in a data-driven way.
https://github.com/alexcasalboni/aws-lambda-power-tuning
28. DB Connections Management
Serverless works best with services rather than connections.
Connection management:
• Application connection pooling
• RDS Proxy
• Amazon Aurora Serverless v2
• Data API
• Dynamo DB
• https://aws.amazon.com/blogs/database/best-practices-for-working-
with-amazon-aurora-serverless/
29. Thank you!
For more information, contact
Dima Pasko
Solution Architect II
Dmytro_Pasko@epam.com
https://www.linkedin.com/in/dimapasko
Notas do Editor
Hello ZED Conference 2021Let’s talk about …
Based on real life experience in Insurance domain
Kharkiv, Ukraine
Solution Architect
Passionate and successful Architect with over 17 years of experience including 6 years of experience in Software Architecture
Experience in Digital Transformation projects with Microservices & Serverless
Multi-cloud experience: AWS, Azure
Next evolution of cloud computing.
Serverless <> not only lambda, it is serverless DBs Engines, Container services, BPMN engines.
Servers not have gone you do not manage them only.
Faster time to market
(Business logic –> API) – >Messaging & Orchestration -> Storage & Databases -> Compute -> Physical Infrastructure
AWS Lambda automatically runs your code without requiring you to provision or manage infrastructure. Just write the code and upload it to Lambda either as a ZIP file or container image.
Focus on most important part of your application
Technology abstraction allows us to focus on building just the pieces of code and configuration that are providing truly unique value for the client.
Productive for the day one
Cost optimized with millisecond metering
With AWS Lambda, you only pay for the compute time you consume, so you’re never paying for over-provisioned infrastructure. You are charged for every millisecond your code executes and the number of times your code is triggered.
At its most basic, the cost case for serverless boils down to utilization. You’ve probably seen the numbers — traditional, on-premise datacenter servers tend to be only 15 to 30% utilized. (We’ve even heard that most large EC2 users struggle to reach this utilization rate as well!) Put the other way, that means 70 to 85% of your server costs are dead weight. Waste.
Аналогия – абонемент в спортзале
No hidden costs:
Security
Platform outdated
(personal story) test environment for 18 teams ~ $400
Scale from zero to infinity and back
Consistent performance at any scale(smooths)
With AWS Lambda, you can optimize your code execution time by choosing the right memory size for your function. You can also keep your functions initialized and hyper-ready to respond within double digit milliseconds by enabling Provisioned Concurrency.
Easy to start new project, very cheap, modularity, elasticity
Experiments, new environment, iteration cycle
A lot of integrations. Event based. Out of the box.
Architecture improvement: breaking the monolith into functions that could be independently deployed, meant that they were better able to split the team up to work on more things in parallel, and to deploy each feature separately
Next evolution of cloud computing.
Continuously improving: ARM + Graviton
Don’t invent a wheel and review AWS resources
Try to search and adopt existing to your case
Also this is a good reason to learn how to draw diagrams for AWS
AWS Well-Architected Framework
The AWS Well-Architected Framework Lens provides a set of foundational questions for you to consider for all of your cloud architectures.
Serverless Lens
Description
The AWS Serverless Application Lens provides a set of additional questions for you to consider for your serverless applications.
Tell how you open AWS console, add workload, grouped questions, download a report
Tell how you open AWS console, add workload, grouped questions, download a report
Serverless can gain polarized opinion starting from “use it everywhere, it’s cool!” to “just a hype, I’m good with my Java 5 + tomcat”And this emotional attitude often drives technology selection
That’s why this slide is more about myths about serverless than about antipatterns
Myth #1: Serverless means “no server and hardware” Servers not have gone you do not manage them only.
And sometimes this abstraction leaks – for lambda you need to setup required RAM size
Serverless more means “no infrastructure work” – all the infrastructure maintenance is on provider
Portability, Vendor lock
Myth #2: Serverless == Lambda (AWS Lambda, Azure Functions etc.)
As Serverless means “no infrastructure work”, many of services familiar to you are already serverless. AWS S3 for example.
Amazon enumerates as serverless such services as S3, SQS, SNS, API Gateway, DynamoDB
Even modification of Aurora falls into this category
Myth #3: Serverless is cheap, definitely cheaper than serverfull solution
Not always, you always should calculate costs ahead to see if it’s good fit
Not all workloads are suitable for serverless
Example from Insurance domain, predictable loadAd tech, stock exchange – could bad domain example
The Sirens & Odysseus
Antipattern #1: Going stateful (in-memory state)
We are not talking about state saved in external service (caches like Redis, databases etc) – that approach is fine
But accumulating in-memory state is definitely antipattern:
Though lambda instance can be preserved for the next requests (such called “hot start”), it is not guaranteed
After lambda run, lambda instance can be terminated anytime
So the pattern is: if you need a state, store it in external services. For fast access use distributed caches as AWS ElastiCache (managed Redis)
You CAN go with in-memory state if you know what you are doing (lambdas are in warm state, have provisioned/reserved concurrency on – so instances will likely be reused)
Icarus
Myth of Jason and the Argonauts
Antipattern #3: Use your favorite tech stack without paying attention at cost
“I will write this on Spring Boot” can have such downsides:
You might need more memory for lambda than for the same logic written in Go or Python (up to 4 times and more)
Startup can be much slower in comparison to using plain old java or another language
Can be mitigated by keeping lambda at warm state for hot start
Often for cold start the startup time can be longer than processing time itself
Both memory size and startup time add a cost
You are charged on a second basis. Reducing overall duration from 10 seconds to 5 seconds will cut your costs twice
Decreasing memory size (because code in Java was rewritten in Go) by two times will cut your costs twice
As lambda should be small, you can write it in Go/Python/JavaScript even if you are not a Pro in this language
So the pattern is: consider if the cost benefit worth learning a bit of Python
No Dependency Injection frameworks?
King Midas and his touch
Antipattern #4: Using old-fashioned way for orchestration
“I will save a record in DynamoDB from lambda and then Thread.sleep for another service to update it’s status”
Each second if lambda does not do anything, you still pay money
Design for retries
So the pattern is:
Avoid explicit and try to avoid implicit waits
Implicit wait – blocking lambda instance awaiting for response from synchronous calls (RESTs)
Explicit wait – Thread.sleep, polling messages from queues in while loops, checking state in while loops etc.
Use Cloud-Native way of logic organization:
Orchestration using AWS Step Functions
choreography using message brokers (SQS, EventBridge, Kinesis, DynamoDB Streams)
Nested Stacks
Monorepo – one repo for workload
Good to keep order, atomic deployments, PR in one repo, easier engennering best practices
11. AWS Account strategy (Sizing (Account per Team), sharing resources, hard to performance test, limits)
a. See Laura's Blog for some details on Lambda Concurrency issues :https://myconnections.lmig.com/blogs/n0085283/2019/03/14/aws-lambdas-setting-a-max-concurrency-its-consequences
Best practices: - Dashboards
Alerts, Notifications
Sets of best practices