5s backup by 1F 5.5V Super Capacitor
A Capacitor alone isn't enough

A capacitor stores energy \$E=\frac{1}{2}CV^2\$ . As soon as you start to take energy from the capacitor, the voltage drops. You can only charge to 5V, then as soon as you take any energy at all, you drop below 5V. And you say you need 5V for your circuit.

Capacitor and boost converter

For 5V, 0.5A, 4 seconds you need 10J, and a 2.2F capacitor charged to 5V stores 27J, so it has enough energy.  You just need a circuit or module to convert the steadily dropping voltage from the capacitor to something your circuit can use.  This would be a "boost converter".  The boost converter won't be able to use all the energy from the capactor, and some will be lost in convesion, but you'll get most of it. 

Making it work

A capacitor and a boost converter will get you started.  You'll also need a way to automatically switch between your normal power supply and the boost converter when the normal supply fails. If you had a supply which is just a little higher voltage, then you could use diode or, but you don't so you'll need to do something more complicated.