Sobes.tech
Middle+

Task: you are asked to review the code of a new feature, which allows booking a tour (consisting of a flight ticket and a hotel). The features for separate booking of flight tickets and tours already exist, and this task expects a unified method that books the entire tour or nothing.

sobes.tech AI

Answer from AI

In such a task, it is important to ensure the atomicity of the tour booking operation so that either both components (air ticket and hotel) are booked, or none — otherwise, data desynchronization may occur.

Key points for review:

  • Use a transaction that covers both bookings.
  • Handle possible errors at each step to rollback changes in case of failure.
  • Verify that calls to existing booking methods for air tickets and hotels support rollback or cancellation.
  • Log the process for debugging and auditing.

Example in C# using a transaction (pseudocode):

using(var transaction = dbContext.Database.BeginTransaction())
{
    try
    {
        BookFlight(flightDetails);
        BookHotel(hotelDetails);
        transaction.Commit();
    }
    catch(Exception)
    {
        transaction.Rollback();
        throw;
    }
}

If booking methods do not support transactions, implement compensating actions (cancellation of bookings) to rollback already made bookings in case of errors.

Task: you are asked to review the code of a new… - sobes.tech