Reputation: 53
I work as a junior backend developer for a product that has about 100.000 users on average per month. Our senior backend developer suddenly quit and now I'm on my own with still a lot to learn. Hence this beginner's question.
We have a Symfony 3 application connected to a MySQL database (hosted on AWS RDS) using Doctrine and Sonata Admin bundles, running on about 2-4 AWS EC2 instances. Most requests we need to handle are GET requests which return the same data for every user, thus very cacheable, which is why we can serve a large number of users with only 2-4 EC2 instances.
Now I have been tasked with creating a very lightweight "analytics" system, that stores some data for each user every time they use the application. Meaning a POST request that writes to the database for each user every time they use the app.
We sometimes have 20.000 concurrent users in the application. How can I achieve this without our EC2 autoscaling blowing up, or blocking the database? This user data is not time sensitive, so it doesn't have to be written to the database right away. A delay of up to an hour or so is acceptable.
Thank you.
Upvotes: 2
Views: 426
Reputation: 1189
I would recommend using SNS + SQS + Lambda to achieve this. One common design pattern is called “fanout.” In this pattern, a message published to an SNS topic is distributed to a number of SQS queues in parallel. By using this pattern, you can build applications that take advantage parallel, asynchronous processing. For example, you could publish a message to a topic every time the user uses the application. Independent processes (using AWS Lambda), each reading from a separate SQS queue and pushing them into the database.
Image shared from : https://www.jeremydaly.com/how-to-use-sns-and-sqs-to-distribute-and-throttle-events/
Advantages of this design pattern:
Upvotes: 2