When to build it from scratch from a business perspective? This is a complex question, but I’m going to give you a simple answer.
In an ideal world, with unlimited time and resources, you should always build your own software. This will give you full control over features and life-cycle of the software.
Now, of course the reality is that we don’t have unlimited resources. Then, we should build software that’s core to our business. Don’t waste time on implementing low level libraries and frameworks if that’s not core of your business.
Over the past decade in software engineering I learned that you want to start by owning the core of your business with the intention to replace the rest of the software with in house solutions. Off the shelf solutions are great initially since they give you speed and a way to test things out, but at the end you will always want more control, which can only be achieved by owning the software completely. Very few businesses will end up there.
Own what’s core to your business with the intention to own everything eventually.