Click Ok
Click Ok

Reputation: 8862

Stateless and in-instance database

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:

  1. In my case I will host the database in the same EC2 instance, the problem of the Session State will happen?

and another incidental questions:

  1. I don't even need worry about that now because I have only one EC2 instance?
  2. 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?

Upvotes: 1

Views: 160

Answers (2)

Mark B
Mark B

Reputation: 201138

  1. 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.

  1. 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.

  1. 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

helloV
helloV

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:

  • Attach a volume when launching your instance and install your database in the attached volume. For higher performance, you can choose the disk type that gives you fast I/O.
  • Choose an instance type that has sufficient CPU and memory. You can bump up the CPU/memory even after launching your instance (after stopping the instance)
  • You can migrate your DB to RDS later
  • You can consider DyanamoDB but it is a NoSQL DB

Upvotes: 2

Related Questions