Both are working on those separate blocks, and each block contains information about Alice's transaction and it is just a matter of luck which miner solves it?
Mining a block is basically a race, the successful miner is usually the first one to find a valid block and send it to the rest of the network. In one respect, there is some luck involved, because hashing is purely probabilities, it might take you only one attempt to find a valid block or it might take you quadrillions of attempts. But obviously the more attempts you make, the more likely you are to find a valid block, hence why more mining power generally means higher success rates.
Sometimes, two miners find a block at almost the same time and a small fork happens where some nodes see one block first and others see the other, but this is generally resolved as soon as the next block is mined, because the nodes will move to whichever chain becomes longer.
Hi naequuu, please don't create long statements asking whether you understand correctly. Such questions are not inviting answers and hard for others to benefit from. Rather ask an open question about anything that you're in doubt! :) I've taken the liberty to remove your description of Bitcoin, it would be better suited as an answer on "how does Bitcoin work". You can still find the original text in the edit history. – Murch – 2017-08-30T07:15:08.530
Your description was mostly correct except that instead of 'If 51% of other miners agree that his block is "correct", it gets appended to the blockchain, the miner who solved it gets some bitcoins in reward.' I would say "if other miners build on top of the block, it will be part of the longest chain and the miner will be able to spend their reward." Miners essentially do pay themselves, see e.g. https://bitcoin.stackexchange.com/q/57909/5406.
– Murch – 2017-08-30T07:16:22.757