Report this

What is the reason for this report?

Should I have multiple droplets without virtual envinroment, or single droplet with multiple virtual environment

Posted on August 12, 2015

Hi,

By using LAMP image from Digital Ocean, I manage to have a simple PHP web application (for production usage) in droplet, with 0 package installation.

As time goes on, I plan to develop more web application in Python (for production usage too).

I read through https://www.digitalocean.com/community/tutorials/how-to-deploy-python-wsgi-applications-using-uwsgi-web-server-with-nginx , it seems that using virtual environment is highly encouraged.

I was wondering, if I plan to have multiple web applications, should I have multiple droplets (without virtual environment), with each droplet will host 1 web app.

Or, should I have single droplet, with multiple virtual environments?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

The simple answer is to use multiple droplets.

The longer answer is, it depends - there are lots of approaches to this. We can get pretty far down the DevOps rabbit hole on this question. (And apologies if I’m explaining some things you already know.)

You’ll want to isolate your applications from each other as much as possible, but there are many ways of doing this. That article mentions Python’s virtualenv tool, which isolates Python’s library directories per application, but your application could still write over some file another application was using, etc. Multiple applications could live side by side without problems, but the trend in server application development these days is to isolate them so you don’t have to take that chance.

So, multiple droplets is one way of doing this. In that case, I would recommend looking into tools like Ansible (or Chef, or Puppet, etc…) to allow you to set up a machine the same way every time with just what that application needs.

Another way of isolating applications is running them in Docker containers - which you can think of like little application-focused virtual machines running along side each other on your droplet.

Both of these approaches require learning a bit of tooling, and some processes to get them right for production-level deployments, and each have their pros and cons. If you’re a beginner, working on applications that aren’t going to be large-scale deployments - I’d say that you’ll probably be fine with whatever you choose. But the more isolation you can get (with either approach), the less headaches you’ll have down the road.

Thanks. I first thought virtualenv is similar to vagrant / docker, but I only realize they are completely different stuff till I finish setup yesterday.

Will go for single droplets and multiple vagrant / docker approach at this moment, for cost consideration purpose :)

Heya,

Both approaches—multiple droplets for each app and a single droplet with multiple virtual environments—have their pros and cons. The right choice depends on your specific requirements, the scale of your apps, the expected traffic, and your budget. Let’s look at the advantages and disadvantages of both approaches:

Multiple Droplets for Each App:

Advantages:

  1. Isolation: Each app is isolated from others. If one app has an issue or is compromised, it won’t affect the others.
  2. Scalability: You can scale each droplet according to the app’s requirements. For instance, a resource-intensive app can be on a larger droplet, while a smaller app can be on a cheaper, smaller droplet.
  3. Simplicity: No need to juggle multiple virtual environments on one server.

Disadvantages:

  1. Cost: Each droplet costs money. If you have many small apps, it might be more cost-effective to host several on one droplet.
  2. Maintenance: More servers mean more maintenance. You’ll have to keep multiple droplets updated and secure.

Single Droplet with Multiple Virtual Environments:

Advantages:

  1. Cost-effective: You pay for a single droplet regardless of how many apps you host on it (as long as it has the necessary resources).
  2. Centralized Management: One droplet to maintain, backup, and monitor.
  3. Resource Sharing: The apps can share the droplet’s resources. This can be efficient if not all apps have high simultaneous demands.

Disadvantages:

  1. Potential for Conflicts: Different apps might have different requirements. Managing these in separate virtual environments can mitigate conflicts, but you might still run into issues, especially if apps need different system-level services or configurations.
  2. Shared Resources: If one app has a traffic spike or uses excessive resources, it can affect the performance of other apps on the same droplet.
  3. Security: If an attacker compromises one app, they have potential access to the environment of other apps on the same droplet.

Recommendations:

  1. Small Projects: If you’re just starting or if these are small projects with low traffic, start with a single droplet and use virtual environments. It’s cost-effective and should be sufficient for initial stages.

  2. Mission-Critical Apps: If one or more of your apps are mission-critical or expected to have high traffic, consider giving them their own droplet. This provides better isolation and allows for more specific scalability.

  3. Diverse Requirements: If the apps have significantly different system-level requirements, it might be simpler to use separate droplets.

  4. Backup and Monitoring: Regardless of the choice, ensure you have proper backups, monitoring, and security practices in place.

In the end, there’s no one-size-fits-all answer. Start with what makes sense for your current situation, and as your projects grow and evolve, you can always migrate and restructure as needed.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.