From the electrical point of view, adding a lithium battery would be the way to go. There are a lot tutorials on how to make your Pi ready for mobile use and if you have it permanently connected to the power supply and only need this as a backup, it should never run out of power.
Adding a capacitor would work, at least in theory, but let's talk about the dimensions first: The Pi 3 draws up to 2.5A (worst case scenario) from a 5V supply voltage. The definition of Farad is As/V. so by inserting current and voltage you get 0.5s from a whole (!) Farad, and only if it can hold the voltage until it is completely discharged... which, well, it simply doesn't. The voltage of a 1F capacitor would have dropped to 4.95V after only 20ms.
So you can see that to realize a capacitor solution for a whole shutdown you would need many F so it is going to a lot much more expensive than using a battery as a buffer. If you are still interested in the capacitor solution you could do some research about the capacitor discharge process. The circuit on the other hand would be super easy, just connect it in parallel to your Pi. So if you really need only a few ms go with the biggest capacitor you can afford. There are so called goldcaps which are quite cheap, but their voltage is low (around 2.3V) so you would have to connect some of those in serial. Just remember that this will also decrease the total capacity! I found a 22F 2.3V gold cap for 5,70€ so with 3 of them you could drive a Pi with around 7F. After 140ms the voltage would have dropped to 4.95V, after 282ms you would still have 4.9V... I don't know about the smallest voltage to drive a Pi but 4.95V (1% drop) sounds kind of realistic to me.
I think you will have to test it by yourself because noone knows what you're up to. I'd still go with the battery, though.