Section 19: AWS Integration & Messaging: SQS, SNS & Kinesis: SQS Flashcards
SQS
Patterns: When we sart deploying multiple applications they will need to communicate with each other. Synchronous and Asynchonous/Event Based are two patterns of communication. What’s the difference?
- Synchronous is described as application-to-application. Ex: you have an app for buying and an app for shipping and they are in direct contact with each other.
- Asynchronous /Event based is described as application-to-queue-to-application. Ex: you have an app for buying, and a queue, and an app for shipping. When someone buys something, that item goes into a queue for shipping, and the shipping app picks the item up from the queue.
If you have sudden spikes of traffic, might that be more like to become a problem for your synchronous or your asynchonous application architecture pattern?
Other things being equal, it’s more likely to be a problem for your synchronous application. Ex. if you need to encode 1000 videos where usually you only encode 10. This is why people are so into the idea of decoupling applications.
what kind of model is it when you decouple an application using:
1. SQS?
2. SNS?
3. Kinesis?
4. can these services scale indepently from our applications
answer options: pub/sub, queue model, real-time streaming
- queue model
- pub/sub model
- real time streaming model
- yes
- What goes in the middle, SQS, SNS or Kinesis?
- Is this a queue model, a pub sub model, or a real time streaming model? What going
- SQS
- queue model
- Is SQS a managed SQS service?
- What is SQS used for, coupleing or decoupling applications?
- yes.
- Decouple
What are the two types of SQS queue types? (just names, more details on both will be asked for soon)
- Standard
- FIFO
Will messages in an SQS queue of type Standard occassionally be duplicated?
yes for queue type: Standard. Messages will always be sent at least once, but occassionally they’ll be sent multiple times.
Will messages in an SQS queue of type FIFO occassionally be duplicated?
FIFO gaurantees “Exactly-Once Processing – A message is delivered once and remains available until a consumer processes and deletes it. Duplicates aren’t introduced into the queue.”.
Will messages in an SQS queue of type Standard occassionally come out of order?
Yes. For Standard type SQS queue best effort ordering is used, which means messages will occassionally come out of order..
Will messages in an SQS queue of type FIFO occassionally come out of order?
No. FIFO type SQS queues gaurantee first in, first out delivery. The order in which messages are sent and received is strictly preserved.
What is the limit on the throughtput /number of messages in an SQS queue of type Standard per day?
For Standard type SQS queue: unlimited throughput, unlimited number of messages in the queue. exact quote is “Unlimited Throughput – Standard queues support a nearly unlimited number of API calls per second, per API action (SendMessage, ReceiveMessage, or DeleteMessage).”
What is the limit on the throughtput /number of messages in an SQS queue of type FIFO per day?
For FIFO type SQS queue you can get what is sometimes described as high, and sometimes described as limited, throughput.
* You can get 300 messages per second when you don’t use batch apis (if you use SendMessage, DeleteMessage, ChangeMessageVisibility)
* If you use batch api’s (SendMessageBatch, DeleteMessageBatch, ChangeMessageVisibilityBatch) then those 300 messages would be able to send the data of 3000 messages.
So I think both Standard and FIFO type SQS queues are good for decoupled application, but one seems to be best when order is doing steps in sequence is most important, and the other seems to be best when high throughput is most important. Which is most important when?
- Standard: use this one when throughput between applications is most important.
- Use FIFO when order of events is most important.
Give a use case example of Standard type SQS queue. Can give up to three.
- Decouple live user requests from intensive background work: let users upload media while resizing or encoding it.
- Allocate tasks to multiple worker nodes: process a high number of credit card validation requests.
- Batch messages for future processing: schedule multiple entries to be added to a database.
Give a use case example of FIFO type SQS queue. Can give up to three.
- Make sure that user-entered commands are run in the right order.
- Display the correct product price by sending price modifications in the right order.
- Prevent a student from enrolling in a course before registering for an account.
SQS
- What is the default retention of messages (in days) and the maxium retention of messages (in days)?
- What is the latency on publish and receive?
- what is the data size maximum per messages sent?
- default is 4 days, maximum is 14 days
- low latency (< 10 ms on publish and receive)
- limitation of 256 kb per message sent
SQS producing messages:
- How are messages proced to SQS? (what is the name of the API?)
- How long is a message persisted (how long does a message stay) in SQS?
- What is an example of something you might use SQS for?
- SendMessage API (for what it’s worth, the line reads “[Messages are] Produced to SQS using the SDK (SendMessage APi)”)”)
- The message is persisted in SQS in until a consumer deletes it (though, again, it can stay, presumably awaiting pickup for a default of 4 days and up to 14 days)
- you might use it to send an order to be processed, along with info like an order id, customer id, and any other relevant attributes.
SQS Consuming Messages
1. what aws services do Consumers frequently use?
2. what do SQS consumers do, broadly?
3. how many messages can an SQS consumer receive at a time?
- ec2 instances, servers, aws lambda
- poll SQS for messages, process any messages, delete messages
- 10 messages at a time
- What is an example of what an SQS consumer might do when in it’s processing stage (hint, what’s one place a message might need to go)?
- What is the API SQS Consumers use to delete messages?
- They might insert the message into an RDS database
- DeleteMessage API
Say you have multiple SQS EC2 Instance consumers.
1. Do such ec2 instance consumers receive and process messages sequentially, or parallely?
2. If you were experiencing throughput issues, would you scale such consumers vertically or horizontally to improve processing?
3. are messages gauranteed delivery to at least one consumer?
4. are messages gauranteed to be received in the order in which they were submitted?
5. who deletes messages, producers or consumers?
- parallely
- horizontally
- yes
- no, best effort will be made at ordering though
- consumers
Can you use SQS with an auto scaling group?
yes
What are some key aspects of the design for using SQS with ec2 instance consumers and an auto scaling group for the ec2 instance consumers?
- your ec2 instances poll your SQS queue for messages.
- your ec2 instance has an associated auto scaling group.
- your auto scaling group uses a CloudWatch alarm to know when to scale.
- your cloudwatch alarm is based on a cloudwatch metric - queue length (ApproximateNumberOfMessages) in your SQS queue.
What is an example of how SQS can be used to decouple a front end from a back end.
requests -> front end web app with an asg -> send messages using SendMessage API to an sqs queue -> back end app (which also has an asg) receives messages via ReceiveMessages API -> data gets inserted into something like an s3 bucket or whatever.
SQS and Security: how is encryption handled:
1. in flight
2. at rest
3. client side?
- in flight encryption using https api
- at rest encryption using kms keys
- client side encryption if the client wants to perform encryption / decryption itself
sqs security: how is access controlled? (just name the two methods, i’ll ask for info on those methods soon)
- access controls
- sqs access policies
sqs security: what are access controls?
- iam policies to regulate access to the sqs api
sqs security: what are sqs access policies?
they’re similar to s3 bucket policies. They’re useful for cross-account access to sqs queues, and for allowing other services (like SNS and S3) to write to an SQS queue.
SQS queue access policy: how do you get cross account access so an ec2 instance can poll an SQS queue for messages? Give result in SQS queue access policy form. The SQS queue id is 444455556666. the ec2 instance account id is 111122223333 and it’s region is us-east-1.