Reputation: 8862
I'm new to AWS and I starting to test creating a EC2 instance. I plan deploy a simple ASP.Net website, and I will host my database directly on the EC2 instance.
Now, I hear that in the "cloud" I need take care when develop the ASP.Net application because it needs be "stateless", I cannot rely on ASP.Net SessionState to maintain data.
My usual approach is then store the state in the database, because (in theory) any ASP.net app will access the same database.
That's my main question:
and another incidental questions:
Upvotes: 1
Views: 160
Reputation: 201138
- In my case I will host the database in the same EC2 instance, the problem of the Session State will happen?
No you won't have session state issues in this scenario. You have session state issues when a single user's HTTP requests are distributed across multiple web servers. And even if you have multiple web servers you can use sticky sessions, or a distributed session store that uses something like Redis, to mitigate that issue if you don't want to go fully stateless.
I suggest you take the time to understand what stateless web architecture is, and exactly what problems it is attempting to solve. Just moving your session from one place (web server) to another place (database server) doesn't make your application stateless, and might result in simply moving your scalability bottleneck from one location to another location.
- I don't even need worry about that now because I have only one EC2 instance?
Correct, you don't need to worry about it with just one EC2 instance. Just like you don't have to worry about it when testing your app while it is running on a single laptop.
However if you think you will need to scale your application across multiple servers in the future in order to handle higher load, then you need to be at least thinking about how you will accomplish that now, while you are in the early stages of designing your application.
- In future I probably will move my "in-instance" database to a RDS. In that case, I can safely store Session State on database, or there are better solution?
If you intend to store session state outside of the web tier (which will enable easy horizontal scaling and load distribution of the web tier), then you could use an RDS database. However that could lead to fairly heavy database IO if you have to load and update that record every time a request is processed. I can see that being a real bottleneck.
I would highly recommend using a Redis server in this scenario, instead of a relational database. Amazon's managed Redis service is called ElastiCache.
Upvotes: 3
Reputation: 52463
Yes, you can install/host the database in the same instance. Only requirement is when you launch your instance, make sure the AMI is EBS backed. When you launch an instance, you will launch it from an AMI. If the AMI is EBS backed, your root volume persists even when you stop the instance. Amazon EC2 Root Device Volume
There will not be any issue if you run your database in the same instance if your DB does not require lot of compute and memory resources. I suggest, you:
Upvotes: 2