Much like many things in bridge, there is a rule of thumb for ducking. Assuming a 3NT contract, you can follow the Rule of Seven:
Subtract from seven the total number of cards that declarer and dummy hold in the defenders' suit and duck their lead of the suit that many times.
In your example (again, assuming a contract of 3NT), you should duck the lead once and win the second round. If the outstanding cards are distributed 5-2, one duck will be enough to break the opponent's communication in that suit. If they are distributed 4-3, you can't disrupt the communication, but they could only ever cash three tricks in the suit if they get in.
There is one big exception to this, and that's not to duck if there is another suit that is worse than the led suit. Say the hands are like the following in a 3NT contract:
♠️ xx
♥️ Qxx
♦️ KQJxx
♣️ Qxx
♠️ Axx
♥️ AKxx
♦️ Axx
♣️ xxx
If the opponents lead a spade, you should not hold up. If you let the opponents win the trick and they switch to clubs, you could potentially go down before you can get in. Better to just win the trick and cash your nine/ten tricks immediately rather than duck the spade.