How to best setup an API backend


I have an app that has an API it calls. The API get’s called multiple times a second from the app’s users. One aspect of the API calls is the recording if usage statistics.

Currently I have all of this managed on a dedicated server at a local hosting company. I have however noticed that the CPU-loads tend to get pretty high on peak usage times.

I am wanting to upgrade to a more professional solution. From what I have researched it would be wise to create multiple droplets.

  • a droplet for the web server that serves the API (PHP-scripts) and
  • a droplet that hosts the mariaDB/mySQL database

In the future I can clone the web server droplet to handle its load demands. I assume I can then use the Digital Ocean’s load balancer to mediate between the droplets.

But what about the mySQL database droplet? I can’t clone the database to balance it’s load - I would have duplicate data. How do I best go about dealing with it’s load? Same question is regarding the size. At the current rate the database grows approx. 5 GB a month. The more users come the faster it will grow. Is my only solution to expand the droplet’s disk space, or can I then split the database across multiple droplets? The usage statistics database itself constists of mainly 3 very large tables. I am sure I could split each table on a separate server, but that should make JOIN statements difficult.

I realize that some of these questions are very future-oriented, but if I am already setting everything up new, I want to setup up every thing so that it is less work when things need to expand. I am trying to prevent time-costly caveats unknowningly.


Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Thank you very much - this was very helpful.

One more question - what droplet sizes would you suggest? Up until now I have put everything on one larger server, so I have no idea what requirements the two instances would need.

Currently have 15 requests / sec. which peaks around 40 req. / sec. And the database is currently at 15 GB with approx. 105 mil. records (InnoDB).

Is something like: a 2GB, 1 vCPU enough for the web server instance and a 3GB, 1 vCPU (later with block storage attached) enough for the database instance?

Which is more RAM hungry? Database or web server?


Hi @jk8db1e0d

For the database storage you can attach a block storage device to your droplets and mount it where your database stores its data that is usually /var/lib/mysql.

For scaling your database workload you can use percona XtraDB Cluster which allows you to run three droplets or more and distribute the workload on all three of them also it can scale very well in the future.

I hope this helps you, please reply if you still have any questions.