Inconsistent data retrieval from Airtable API causing duplicate records

I’m working with Airtable’s Node.js SDK and running into a frustrating issue. My app checks if a booking already exists before creating a new one, but sometimes the search fails to find existing records.

Here’s my lookup function:

findBookingByReference: async (refNumber) => {
    let bookings = await reservationBase('Bookings').select({
      view: 'All Records',
      filterByFormula: `{Reference Number} = "${refNumber}"`,
      maxRecords: 1,
    }).all();

    return (bookings.length > 0) ? bookings[0] : null;
},

And here’s how I use it:

let existingBooking = await findBookingByReference(booking.reference);
if (!existingBooking) {
  addNewBooking(booking);
} else {
  modifyExistingBooking(booking);
}

The problem is that sometimes the API returns nothing even when I know the record exists. This causes my code to create duplicates instead of updating existing entries. Has anyone experienced similar reliability issues with Airtable queries? Could this be related to timing or API rate limits?

Yes, it sounds like you’re encountering a race condition. I’ve faced similar issues where rapid simultaneous requests lead to the lookup function being executed before AirTable has fully processed the previous writes. This can create instances where the records are not immediately accessible, resulting in unintended duplicates.

To mitigate this, I implemented a retry strategy with exponential backoff. After inserting a new record, I wait for around 500 milliseconds before performing any lookups. If a lookup fails unexpectedly, I retry two to three times, increasing the delay with each attempt. Additionally, consider utilizing unique constraints or Airtable’s upsert feature to prevent duplicate entries. Keep in mind that performance can degrade during peak usage, but this method significantly reduced the number of duplicates in my applications.