What should the safety margin of these habitat? Also how much redundancy the colony system should have? These are excellent questions though except in generalities, we can't answer them here.
Safety Margin
A simple, naive answer would be a factor of 2. For example, an oxygen system is capable of handling 10,000 m^3 of air per day but the operational requirements are only for 5,000m^3 per day. If you have two such units, your habitat can tolerate the complete failure of one oxygen system and still operate indefinitely. Granted, you want to get that fixed as quickly as possible but you have enough leeway to fix it properly instead of some rushed hack job.
Redundancy
A simple, naive answer is "Two of everything" and "At least two ways to do everything". You'll see this play out in large computer systems where systems architects are perpetually on the watch for single points of failure and eliminating them as much as possible. Some times, these single points can't be eliminated but in such cases, lots of engineering work goes into making sure the equipment/system is incredibly robust. If the habitat only has a single airlock then that airlock will be incredibly resilient to bad bumps, overspeed docking, torsion moments, vibration, accidental kicks by ingressing astronauts, etc, etc, etc.
Nature of Failure
As other have pointed out, when a system fails, especially in an environment like space, it should fail-safe, ie, the life support system doesn't vent the remaining atmosphere to space when it fails.
Disasters are rarely the result of single large failures. Most often they are the result of a string of small mistakes and failures that individually are easy to counter but collectively cannot. This has proved true in practically every domain where safety is a concern. Big failures, while an omnipresent possibility, don't happen nearly as often as failure cascades where a small failure of one component leads to another failure which leads to another failure until the entire system is compromised and catastrophically fails. A lot of engineering work on the ground will go into designing systems that preclude failure cascades.
In addition to equipment design, training of astronauts is critical. Resilience research has found that it is often the human element that can accommodate failures in the systems. Proper procedures and training need to be in place to fix problems that can't be anticipated or adding the ability to detect a certain error condition would add an unacceptable cost/weight of a particular system.
For further reading about resilience engineering, might I recommend the book "Resilience Engineering: Concepts & Precepts". I've found it a fascinating read about how safety systems degrade and how to treat that degradation.