you get the last insert id based on your connection, and concurrent operations will have different connections, so the case of mixed up keys wont happen. A more real concern though would be if your insert fails, this would mean that getting the last id would fetch the last successful insert on that connection and use it