The 'tx id' is also known as the transaction hash. It is a keccak hash of the transaction data.
This hash is used to uniquely identify the transaction, which is why it's also referred to as the 'tx id'.
The tx id is actually a hash of 3 hashes:
A hash of the 'transaction prefix', which contains information such as the inputs, outputs, and the 'extra' field which contains any payment id associated with the transaction.
A hash of the 'base ringct' data, which includes the encrypted output amounts and the output Pedersen commitments.
A hash of the 'prunable ringct' data, which includes the output amount range proofs and ring signatures for the inputs.
The payment id that you can specify for a transaction is known in advance of creating the transaction. This means you can tell someone to use a certain payment id when sending you a transaction. If a payment is being sent to an integrated address, the payment id is also encrypted so that only the recipient can decrypt it.
The tx id, in contrast, is only determined after you create the transaction. By "create the transaction", I mean select the specific outputs that are going to be spent, choose decoy outputs, and construct the entire transaction payload that is ready to be submitted for mining. You do not have to actually publish or submit your transaction to be mined to determine the tx id.
Since the tx id is simply a hash of the transaction, anyone observing the public blockchain will be aware of the tx id of any transaction on the blockchain.