Are 2 INSERT statements guaranteed to complete sequentially? We've got a system that receives event from clients and stores them in a database.

Each event is saved as an atomic INSERT, and has an id_event which is an auto-incremented primary key.

Our clients can execute a specific action that causes 2 events to get fired in rapid succession:


1) name: 'board-added', boardId: 12344 
2) name: 'board-switched', boardId: 12344


Both events arrive at our server in the correct order.

However, for some reason we keep finding some board-switched events having an id_event that precedes it's corresponding board-added event.

As you can see in the below result set, board-added has a higher id_event than board-switched which is wrong.


{name: "board-switched", boardId: 313994, id_event: 48041136}
{name: "board-added", boardId: 313994, id_event: 48041137}


My question is:

Is it possible that 2 INSERT events, executed sequentially will cause the 2nd INSERT to complete before the 1st INSERT?
It is not guaranteed if they are separate requests that are not in the same database transaction. Given the architecture of modern web apps, if they are separate requests I can almost guarantee that they are not in the same transaction and so are in no way dependant on each other.

A connection-pooled application is likely to accept the two requests with different threads, so even if the requests are issued by the client in order, the second request could insert into the database before the first if execution of the first was slower.