My rather broad solution has always been: let engineers own a part of a stack. Let an engineer own the UI for an app, own the database front-end. Let an engineer own the caching mechanism, let an engineer own the framework.

You give an engineer ownership and let them learn from their own mistakes, rise to the occasion when the stakes are high. This presumes they will have the last word on changes to that sand box that they own. If they want to rewrite it — that's their call. I'm the end they'll create a codebase they're happy to maintain and we will all win.

(And I think they'll be a happier engineer too.)

But then... One of those engineers quit and another one becomes seriously ill and cannot work for a longer period of time...

Spoken like management, ha ha.

It happens. People step in and take over. The company continues.