How can the blockchain keep only one version of the registry equal on all nodes?

Let's say that minor A works on block X, while minor B works on block Y.
Miners A and B both find the hash for their blocks almost simultaneously and, as such, they begin to disseminate their results to the other miners, in order to reach a consensus.

Are all did the miners in the network need such a consensus?

If this is the case, what will happen if a group of miners strives to reach consensus on one block and another group works on another block (given that to each node takes a little time)?

How do they decide which block is added first to the blockchain?

Note that I am pretty new to this field and I am still trying to understand how the blockchain works.