Module 11 - Serverless & Messaging Flashcards
What are the advantages of serverless architecture?
- No infrastructure to provision or manage
- No servers to provision, operate, or patch
- Scales automatically by unit of consumption rather than by server unit
- Pay-for-value billing model (pay for the unit rather than by server unit)
- Built-in availability and fault tolerance
- No need to architect for availability because it is built into the service
What can you do with the API gateway?
you can create, publish, maintain, monitor, and secure APIs
you can connect your applications to AWS services and other public or private websites.
- Host and use multiple versions and stages of your APIs.
- Create and distribute API keys to developers.
- Use Signature Version 4 to authorize access to APIs.
- Use RESTful or WebSocket API
What tasks does the API gateway handle?
traffic management, authorization and access control, monitoring, and API version management
How does the API gateway handle logging and metrics?
It integrates with CloudWatch, sends metrics and log messages there.
What metrics can the API gateway send to CloudWatch?
- Number of API calls
- Latency
- Integration latency
- HTTP 400 and 500 error
- (also who has accessed your API and how it was accessed)
What is Amazon SQS? What does it do?
Amazon Simple Queue Service.
It’s a fully managed service that processes messages. It stores all message queues and messages within a single, highly available AWS Region with multiple redundant Availability Zones
What is the benefit of an SQS queue?
Unlimited throughput, unlimited messages
isolates the processing logic into its own component and runs it in a separate process from the web application. This makes the system more resilient to spikes in traffic.
you can decouple preprocessing steps from compute steps and post-processing steps –> scalability and reliability.
What are some ways to use SQS queues?
Work queues: regular or FIFO
Buffering and batch operations: smooth out temporary volume spikes without losing messages or increasing latency.
Request offloading: Move slow operations off interactive request paths by enqueueing the request.
Auto-scaling instances: use the queue to determine the load, combine with autoscaling.
What are the SQS queue types?
Standard -
• at-least-once message delivery
• best-effort ordering
• nearly unlimited number of API calls per second
FIFO - when the order of operations and events is critical or where duplicates can’t be tolerated
• exactly-once processing
• a limited number of API calls per second (300)
• only 1 consumer (you can have more if you use GroupID to separate them)
What are some features of SQS queues?
distributed queue system
super low latency (<10ms response)
keeps messages from 1 to 14 days, but the default is 4 days
messages must be small: up to 256 KB of text in any format
supports multiple producers and consumers interacting with the same queue
How is an SQS message consumed?
The consumer polls for the message; the message is still in queue during processing.
Consumer can receive up to 10 messages at once.
Amazon SQS sets a visibility timeout so that other consumers don’t grab the same message (default 30 sec; max 12 hours)
When processed, the CONSUMER deletes the message. If processing fails, the message becomes visible again.
What is short polling?
When call or queue attribute:
ReceiveMessage.WaitTimeSeconds = 0
Default queue behavior.
What happens when you consume from a queue with short polling?
SQS samples a subset of servers and returns only those messages (so maybe you won’t get all messages)
If you have < 1000 messages OR you keep consuming, you will eventually get all your messages.
What happens when you consume from a queue with long polling?
Amazon SQS samples ALL servers. It can wait up to 20 seconds for messages to arrive before responding.
Reduces the COST of using Amazon SQS by reducing the number of calls.
Reduces latency, increases efficiency.
Can be enabled at the queue level, or at the API level using WaitTimeSeconds.
What should you do if you implement long polling with multiple queues?
Use one thread for each queue so your application can process the messages in each queue as they become available. Otherwise, your application will be blocked from the other queues.
How does a dead-letter queue work?
After trying to process a message a few times (when the MaximumReceives threshold is exceeded), the message goes to the DLQ.
Works like any other queue. It must be in the same AWS account and region as the queues that use it.
You should set a high retention so you have time to debug.
What are some use cases that DON’T work for queues?
Selecting specifics messages
Large messages
What if I want to pass giant messages?
Store them in S3 and just pass a reference to the message.
What is Amazon SNS?
Amazon Simple Notification Service is a fully managed messaging service for both application-to-application (A2A) and application-to-person (A2P) communication.
Provides a low-cost infrastructure for the mass delivery of messages, predominantly to mobile users.
Pub-Sub model.
Subscribers get all messages (unless using a filter feature)
How do you set up SNS?
Create a topic and policies that indicate who can publish or subscribe.
SNS matches the topic to a list of subscribers for that topic and delivers the message to each subscriber.
Each topic has a unique name that identifies the Amazon SNS endpoint where publishers post messages, and where subscribers register for notifications.
Supports encrypted topics using KMS keys.
What are some use cases for SNS?
Alerts when events occur, like autoscaling.
Push SMS or email to news subscribers
Notifications to an app to indicate an update is available
What are the SNS notification types?
- HTTP or HTTPS
- SMS clients
- SQS queues
- Lambda function
- Kinesis Data Firehose
Characteristics of SNS
- best-effort order
- can’t recall a message after successful delivery
- You can use an Amazon SNS Delivery Policy to control the retry pattern
- To prevent messages from being lost, all messages are stored redundantly across multiple servers and data centers.
- an unlimited number of messages at any time.
- applications and end-users on different devices can receive notifications by Mobile Push notification
- access control mechanisms to ensure that topics and messages are secured against unauthorized access
What are some SNS retry policies?
linear geometric exponential backoff maximum and minimum retry delays other patterns...