The best way to avoid power failure for a Raspberry is to have a UPS system, this power bank enables to power the PI (Limited to 2A per port) and let you the time to switch it OFF when you have an electricity outage.
It has an Always ON mode, with this mode the power bank doesn’t stop to supply energy even if the requested current through the USB port is very low. Other power banks may stop providing current depending on its level.
It can be used with Raspberry Pi, note that for the Raspberry Pi 4, Raspberry advises using a 3A power supply. This power bank provides only 2A per USB port. So you will have to be careful with the power consumption of the peripherals used with the PI.