Im wondering on what always the longest chain is based on. Is it on how many blocks or on how many transactions have been included.
Most people will tell you that it is based on how many blocks are in the chain. As a general rule of thumb that's a reasonable explanation, but technically it isn't correct.
The "longest chain" rule is actually based on the total proof of work. Usually blocks generated at the same block height all have the same difficulty target, so more blocks means more proof of work. However, if someone were to go back to the genesis block and try to generate several hundred thousand blocks at a MUCH easier difficulty target than the existing blockchain, their chain would still be "shorter" even if it had more blocks because it would have less total difficulty.
1st chain has 6 blocks and every block has 100 Transactions (total 600 transactions)
2nd chain has 4 blocks and every block has 400 transactions (total 1600 transactions)
Which is now the longest chain and on which are miner now looking on?
Assuming that they all the blocks were generated at the same difficulty target, the 1st chain is the one that miners would choose to work on. Choosing the 2nd chain would result in all other miners rejecting your block, and therefore you would waste your effort (and money) trying to build on it.
How is it if two blocks are being published at the same time. One block with 100 transactions and the other block with 200 transactions included. Is the latter one taken or are miner not looking on the transactions included in the block?
The intention is for miners to use the first block they receive. So some miners would receive the 100 transaction block first and would build on top of that. Other miners would receive the 200 transaction block and build on top of that. Eventually, a miner would solve a block and broadcast it. This would make the chain they were working on now the "longest". All miners that were working on the other chain would abandon it and switch to this new longest chain. The block that didn't get built on top of would be considered "orphaned".
Wow, thanks for the long explanation!!! I got it!!!