I'm working on an iOS app that makes extensive use of databases, where users will be able to sync their data to a server. However, I'm terrified of the event that if too many users start using the app, the servers will no longer be able to handle it. I'm not a server guy at all and am not too familiar with how that works, but my question is, why do servers get overloaded and how can that be prevented? Does it have to do with who my server host is? Or is it about the efficiency of my code? If my host is a reliable server, such as Amazon AWS, am I still at risk for server problems? Bottom line is, does it have to do with the way I implement my code, or does it have to do with who my host is?
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.
This is a very vague question. They go down because...well, you overload them and they don't have the capacity to handle what you're throwing at them.
Think about it this way. If you have a fire, do you put it out with a garden hose, a squirt gun, or a tanker truck? Any of them can put out small fires. Big fires need more capacity.
How do you prevent it? You test. You plan for the projected load.
If you're talking about databases, you talk to a database person if your load is projected to outpace what you can handle. You need to plan out how to split tables up so you can distribute it over multiple servers, you plan for sharding, you can set up read-only servers to help with reads, master/slave setups...or you look at the underlying technology and see if a "NoSQL" server alternative can handle your needs better. And you look at where the data requests come from, to see if you can distribute your servers to be more geographically conducive for your user's requests.
There's no set answer to this because it entirely depends on what your application does, the kind of data it handles, and what you're pulling from the database.
EDIT - you asked specifically about Amazon, if there's a danger there. Amazon is like Lego. You can use their tools to build robust implementations, sure...and you'll pay extra for it. Or you can run it all off one instance and tie it to their proprietary database system. You can get your application to "work" and it still may not be fully robust. Plus Amazon isn't magic. Instances degrade, die without warning, etc...so to answer that part of your question, yes, your data is still in danger when using Amazon unless you architect around possible failures. You can set up multiple database servers spanning multiple regions as failovers, and it gets quite complicated. That's why there are people paid up to and past six figures to just work with databases. They architect around these problems for a living, and Amazon is not powered on unicorns...they do have failures.
That's pretty general. It can be:
There are several other reasons a server might fail due to load, but these cover a lot of the cases. They also cover the performance of your server, its network link, its reliability in general, and the server software you are running.
Because there're not enough resources to supply the demand. Having a single server on the backend can get overloaded by HTTP requests, for example, and in eccense, cause a denial in service.
You prevent this by fronting your services with tools like Apache and use a load balancer to distribute requests to free servers or servers with less load. The same can be done for the database, scaling horizontally or vertically (sharding)
More with your server hosts, but code can cause it too.
Depends, who is responsible for setting up your servlet container and how it's configured to supply requests. However, I'm not familiar with AWS and therfore can't give a adequate answer here.
DOS is usually due to lack of resources on the hosts side. However, if code is poorly written and designed, it will cause it as well.
For example, if you code too much controller/business logic in PSQL, you could overload the database and prevent queries from returning in a timely manner and thus result in DOS.
You could also write code which uses excessive connections on the database and have an issue where connections are no longer supplied causing DOS.
These two examples aren't necessarily an issue as a result of lack of resources, but more so an issue with not making effective use of the tools being used. Both sides are important and there are many ways to encounter DOS.
However, a good initially designed model can take you a long way. If you're unsure how to design your code, I would start by checking out MVC and SOA. Good Luck!