Inconsistent query results from Airtable API causing duplicate records

I’m working with the Node.js Airtable library and running into a weird issue. My code searches for existing records using filterByFormula but the results are inconsistent. Sometimes it finds the record that should be there, other times it returns nothing even when I know the record exists.

Here’s my search function:

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

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

I use it like this:

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

The problem is that when the search fails to find an existing record, my code creates a duplicate instead of updating the original. This happens randomly and I can’t figure out why. Has anyone experienced similar issues with Airtable’s API reliability?

Had this exact issue. It’s Airtable’s eventual consistency - the API doesn’t always reflect changes immediately, especially with rapid calls or fresh records. Fixed it by adding a small delay between operations plus a retry mechanism. Also switched to using record IDs instead of searching by field values whenever possible - way more reliable. Check if your Reference Number field has formatting issues or hidden characters that break the string comparison. I’d add logging to capture the exact refNumber you’re searching for and compare it against what’s actually in Airtable when searches fail.