0
votes

I have t2.micro EC2 instance running on AWS. To handle spikes in traffic I have created auto scale group which dynamically increases and decreases EC2 instances from an AMI. Everything is fine till here. The problem is my user login database is in same EC2 instance. When new EC2 instance is spawned it does not contain newly added user in primary EC2 instance. And if new user creates account in new instance, it is lost on the instance termination. Is there a way to have single EBS volume for all the instances?

Please point me towards some useful resources on building scalable web apps on AWS.

1
I assume your users are stored in a database, but the way you say it is linked to the OS, I wanted to confirm that all your application data and application users are stored in an actual database, not using OS users. Is that right? - Caesar Kabalan
Yes users are stored in real database. - charles bell
Is your database also stored on the same EC2 instance? Why are you allocating an OS login to users? What are the users doing on your system? Feel free to Edit your question to provide more details. - John Rotenstein

1 Answers

1
votes

The problems you are facing are the primarily reasons why this pattern (all in the same instance) is discouraged. This works while your app is small and is not receiving a lot of traffic.

What you should do instead is to extract your database from the app instances and move it to RDS (being it semi-managed will prevent you from a lot of tasks like server patching, regular backups, configuring replica set, etc). Also RDS will provide you with easy multi-AZ deployment that will help you achieve real fault tolerance. This step is optional though - you could just spin up a new EC2 instance and manually install your DB there (but keep it dedicated to DB purpose).

You architecture should look similar to the following diagram;

ELB ---> INSTANCE 1 --> RDS DB INSTANCE
     |                       ^
     |-> INSTANCE 2 ---------|
     |                       |
     |-> INSTANCE n ---------|

You should keep your instances as stateless as possible if you want to scale. The same approach applies to files that you store in the instance it self; you should move them to S3 (or if available on your region you can also use Elastic File System)