Having Database and Web Server on single EC2 Instance

Having Database and Web Server on single EC2 Instance

Having Database and Web Server on single EC2 Instance:

On this post we’ll see advantages and disadvantages of Having Database and Web Server on single EC2 Instance. Recently when I was working with one of the client, they were planning for migrating their systems to AWS EC2 and they asked me a simple question “Can we have Database and Web server on single EC2 instance? What are all the advantages and disadvantages of having Database and Web Server on single EC2 instance?”   There are several things needs to be considered to answer this question. We thought of document it which can be helpful for the future reference.

Advantages of having Database and Web Server on single EC2 Instance:

Category Advantages
Security No Advantages
Performance

Communication easier between App server and DB Server as both are in same host

If the application makes a large amount of database queries, a considerable amount of network load can be removed by keeping it all on the same system, keeping the response times low.

On AWS if we have App and DB on same machine we need not worry about the region, otherwise we should make sure both DB and App servers are in same availability zone and region.

Load Balancing

On AWS we can get the benefit from Auto Scaling

Maintenance

It makes easier to maintain all App and DB from one place

HA & DR

No Advantages

Cost

Since App and DB sharing the same host it reduces almost half of the price

Scalability

We start using the application and database and we’ll add more resources when required in future using Auto Scaling

 

Disadvantages of having Database and Web Server on single EC2 Instance:

 

Category Disadvantages
Security

Webserver may need to be available for Public internet access and taking untrusted input from anonymous users.

If web server gets compromised then there might be high chances that attacker can get root access on database server too

Performance

Both the web server/app and SQL Server would cache requested data in memory and it strains the cache performance by running them in the same memory space.

May impact CPU cycles as sharing it between App and database

Huge I/O impact when we need to share the Disk between App and Database files

Usually Application and Database servers are having the different hardware requirements.
Database servers fare better with a lot of memory and a really fast disk array while web servers only require enough memory to cache files and frequent DB requests.

Load Balancing

It shouldn’t be a problem as long as we are having a proper estimations on App and DB server resource utility, but an unbalanced resource utility might causes a App / DB hang or interruption

Maintenance No Disadvantages
HA & DR

More recovery time required in-case of any disaster

Cost

Due to performance concern we can only have the databases related to the application sharing the instance, if we have a dedicated DB instance it can serve multiple applications effectively.

Scalability

It is easy and relatively cheap to add web servers and put them into cluster to handle
increased traffic It is not so easy and cheap to add data servers and cluster them.

 

Note: Please help us if we are missing anything. Please drop your suggestions in comments.

Summary:

Choose Database and Web Server on single EC2 Instance:

  • For a cost effective and low traffic / light weighted applications
  • Make sure using the least privilege accounts as there are high security risks
  • We can get a benefit from Auto Scaling

Choose Database on Web Servers on Different EC2 Instances:

  • For a good Scalability, High Availability, Performance and Security
  • Make sure instances are in Same availability Zone in Same Region
  • We can get benefit from ElasticCache

 

Posted in Database Design, SQL Server DBA | Tagged , , , , , , , , , , , , , , , , , | Leave a comment

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz