The API docs states that message ids are unique:

Although I just discovered that it's not true. Hence the question: how are they work? Are ids are unique to a chat or combination of a chat and a client? If I'd get the same message on a different client (an instance of TDLib) will message have the same id, or it will be completely different?
Here is an example of an incoming update:

And here is a message stored in my DB:

This is really confusing. Thank you in advance!
Ok. I've found another doc where it clearly states that the message id is unique to the parent chat.

Yes, all message identifiers are defined inside a chat and they are unique only for that chat.
If you'd get the same server message on a different client for the same user, then message will have the same id. This is not true for local messages and for messages received by different users.
@levlam thank you for the clarification!
Most helpful comment
Yes, all message identifiers are defined inside a chat and they are unique only for that chat.
If you'd get the same server message on a different client for the same user, then message will have the same id. This is not true for local messages and for messages received by different users.