1/47
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Serverless Computing
an execution model for cloud computing environments where the cloud provider executes a piece of code (a function) by dynamically allocating resources.
aka Function as a Service
difference from server-based computing is that in serverless a layer of abstraction is added on top of cloud infrastructure such that the application developers do not need to provision and manage the underlying infrastructure required for execution of code.
Popular FaaS offering from AWS
AWS Lambda
In FaaS, functions are triggered by
events
When a function is triggered by an event, the cloud provider launches a container (e.g. Docker) and executes the function within the container.
Monolithic Application
All functionality in a single process that runs on a server. Scaling is done by replicating monolith app on multiple servers.
Microservices-based Application
A separate microservice is used for each functionality (comprising multiple functions). Each microservice runs on a server or container. Scaling is done by distributing and replicating the microservices across multipe servers/containers
Serverless Application
Microservices broken down into functions, where each function is deployed separately in a serverless platform or FaaS. Scaling is taken care by the platform.
Cloud Services for Implementing Serverless Applications
Service Static App → S3
REST API → API Gateway
Execute Code on Demand → Lambda
Store and Retrieve Data → DynamoDB
Authenticate Users → Cognito
Translate URL → Route 53
Pros of Serverless
Low operational cost
Low maintenance
Scalability
Availability and fault tolerance
Cons of Serverless
No control over the infrastructure
Time limits (to execute the function)
Vendor lock-in
Not suitable for all cases
Master Data
data that doesn’t change much
Transactional Data
data that changes often
What is the Amazon data warehouse
Amazon Redshift
Messaging Queues (AQS SQS)
can be used between the data producers and data consumers for asynchronous processing or load leveling.
Queues are useful for
push-pull messaging where the producers push data to the queues, and the consumers pull the data from the queues
Load Leveling
a queue-based, passive strategy for smoothing out traffic spikes by buffering or deferring requests during peak times and processing them later during lulls
Load balancing
a real-time, proactive approach to distributing incoming traffic across multiple servers to prevent any single server from becoming overwhelmed and to maximize resource utilization
Multiple consumers can make the system more robust as there is no ___
single point of failure
Load balancing between consumers improves the system performance as multiple consumers can
process messages in parallel
Priority queue pattern is useful when __
you want to process messages differently depending on their priority.
Command Pattern
•Purpose: The command pattern focuses on a single instruction or task executed by a specific service. It is used when you want to send a message or command to a single microservice or function to perform an action.
•Execution: The command is sent to one target (e.g., a Lambda function in AWS, Azure Function, etc.), and only that specific service handles the task.
•Example: A user uploads a profile picture, and the service (like an AWS Lambda function) resizes the image and stores it in a storage service (e.g., S3). Only one service is responsible for this task.
•Scaling: While the service is automatically scalable in serverless environments, the command pattern deals with one-to-one communication, where only one service is involved in processing each command.
Command Pattern is useful when you want to
decouple a sender or client who invokes a certain operation from a receiver or worker who performs the operation.
e.g. a single lambda function (command) can be invoked by different event sources which can then invoke multiple lambda functions
Fan-Out Pattern
•Purpose: The fan-out pattern is used when you want to distribute a single event or message to multiple services or functions for parallel execution. It is useful when the same event needs to trigger multiple actions simultaneously.
•Execution: An event triggers multiple serverless functions or services, each performing a different task in parallel. It often uses messaging services like SNS (Simple Notification Service) or EventBridge in AWS to broadcast an event to multiple subscribers.
•Example: A user uploads a video, and the event triggers different services: one service processes the video, another generates thumbnails, another sends a notification to the user, and another updates metadata in the database.
•Scaling: The fan-out pattern inherently supports parallelism and one-to-many communication, where one event is fanned out to multiple services, each scaling independently to handle its specific task.
The Fan out pattern is useful when
you want to perform multiple actions or invoke multiple services or functions, while the event source supports only a single target.
Data Source vs Data Sink
A data source is where data originates, such as a user input, sensor, or database, acting as the starting point in a data flow.
A data sink is the destination for that data, where it is stored, processed, or displayed, serving as the endpoint in the data flow.
The key difference is the direction of data movement: sources emit or provide data, while sinks receive or consume it
Pipes and Filters pattern
pipes/queues are the connections between the filters/workers (processing components).
Benefits of Pipes and Filters Pattern
each task can be scaled independently, parallel processing of tasks, more reliable/fault-tolerant because even if some workers fail, the entire pipeline doesn’t fail.
AWS Lambda
a serverless offering from Amazon Web Services (AWS). Lambda is a compute service that lets you run code without provisioning or managing servers.
In the push model..
an AWS service (such as S3) publishes events which invoke the lambda functions
In the pull model
AWS Lambda polls the event source and then invokes the Lambda function when records are detected on that source. The pull model works for poll-based event sources (Kinesis, DynamoDB streams, and SQS queues KNOW THESE THREE)
In AWS Lambda, you can have at the most ___ concurrent executions across all the functions in your account (account concurrency limit)
1000
Function concurrency limit
concurrency for a function out of the unreserved account concurrency limit
For event sources that aren’t poll-based, you can estimate the number of concurrent invocations of your Lambda functions using the formula
Events/Requests per second * Function Duration
For poll-based event sources that are stream based (Kinesis or DynamoDB streams) the concurrency is equal to the number of
active shards
shard
a term used in the context of databases and distributed systems to describe a horizontal partition of data in a database or data stream
Database Sharding
a technique used to distribute the data across multiple servers or instances to improve performance, scalability, and reliability.
For poll-based event sources that are not stream based (SQS queues)
each message batch can be considered a single concurrent event
AWS Lambda has a timeout limit of …
5 minutes
Horizontal vs Vertical Sharding
Horizontal sharding splits a database table by rows, distributing different subsets of rows across various shards
Vertical sharding splits by columns, distributing different sets of columns into separate shards
Timeout makes the serverless computing model more suitable for
real-time or short running operations rather than long-running batch operations
A container helps in
isolating the execution of a function from other functions
when a function is invoked for the first time, or after a long time
a container is created, the execution environment is initialized, and the function code is loaded
The container is reused for subsequent invocations of the same function that happen within a certain period
The functions should be designed to be stateless
Any application state should be stored in
external resources such as a DB, cloud storage, or cache
Stateless communication
a method where each request is independent and does not rely on past interactions or stored server information
Cold Start / Cold Function
When a function has not been executed for a long time or is being executed for the first time, a new container has to be created, and the execution environment has to be initialized
Cold start can result in a
higher latency, as a new container has to be initialized
Warm Function
The cloud provider may reuse the container for subsequent invocations of the same functions within a short period
Warm function takes __ time to execute than a cold start
less
You can keep functions warm by
invoking them periodically