When we draw events that happen in two processes, we don't know what event causes one another in what time. The diaram like the following seems benign but it definitely causes some confusion.

So Leslie Lamport suggested the following diagram instead:

Here, for P1 raises events x, y, z in order, meaning that x might have causes event y, or perhaps it didn't.
Communication between process is also depicted as events as follows

Here, s is probably "message received" event, so is z whereas p and q are "message sent" kind of event. And x, y, v are internal events.
Given two events A and B, we say A happened before B if any of the following is true:
A->C, and C->B, then A->B (transitive closure)Let's say we have three people in the chat room: Migo, Kay and Carl. Imagine the following situation.
1) Kay sends message saying "Migo is stinky"
2) Migo receives and replies saying "Fuxx you"
But then how do we make sure, from Carl's perspective Kay's message receives arrives first and then Migo's one?
Turns out, there is no guarantee in distributed system unless you have some mechanism.
So, the following could happen.

This phenomenon is known as Causal anormaly.
Happens-before relation is the smallest relation. What it means is it CANNOT confirm if A happens before D from the following:

We know:
(A -> B)(B -> C)(A -> C) (D -> C)Let's find happens before relationship from the following:

There are happens-before relationships for the following events
P->SX->ZP->ZU->RZ->RAnd the like.
But what about Q and R?
We cannot tell is Q happens before R and nor can we say R happens before Q.
When this is the case, we say they are concurrent, also denoted as Q||R.
Happens-before relation is also called Irreflexive Partial Orders - or irreflexive version of partial orders in math.
Partial orders are two things glued together.
a set S
a binary relation, usually (but not always) written <=, that lets you compare things from S and has theses properties:
Reflexity: for all A that are in set S, A is less than or equal to A
Anti-symmetry: for all A and B that are in set S, if A<=B AND B<=A, then A=B
Transitivity: for all A,B,C that are in set S, if A<=B and B<=C then A<=C.
Think of set of events mentioned above like (Q,S,X,Z) as the set S in the partial order.
We can check Transitivity, Antisymmetry are right there but Reflexivity is not because for that to be true, it would need to be the case that given an event A, A happens before A.