OTP is a framework for building robust applications. It comes with a number of “components” to achieve this. Notably, supervisors and gen_* behaviours. These are just code that uses best practices that has been developed over the years. If you try to implement it yourself you’d implement the basics of an OTP behaviour anyway.
Many years ago, in the erlang world, OTP applications wasn’t a given and many projects are created without it. I attribute this to OTP not being pushed enough and under-documented. Note though it is not needed to build software but if you are going to do be running for a long time you win a lot by doing it.
A gen_server, or other behaviours are not fault tolerant per say but it is ready to be “plugged” into a supervision tree which gives you restarts, and hot code loading. The same goes with the other components.
Generally if you have something long-lived (and often for short lived things as well) you will reach for a gen_server because it gives you the ability to use in a bigger context.
There is value in spawning process without them being OTP behaviours and it is sometimes done when you want to complete a quick task but don’t want to run your current process. Normally you use at least spawn_link
or at least spawn
using monitors.
Some links (erlang links but you don’t have to look at the code if you don’t want to :D)
- Design principles of erlang OTP: http://erlang.org/doc/design_principles/des_princ.html
- More explanation about OTP http://learnyousomeerlang.com/what-is-otp
- Errors and Processes: http://learnyousomeerlang.com/errors-and-processes
You might want to skim through http://learnyousomeerlang.com
it helps with understanding how the system developed and why OTP can help.