All posts
Field notes

When a provider has no API: the flight system’s crawlers

14 Sept 20263 min read8 views
When a provider has no API: the flight system’s crawlers

Our answer for those was a crawler. For several years I worked on a flight platform's web service: a B2B system travel agencies used to book plane tickets. Behind it were dozens of domestic and international providers: GDSs, airlines and sales systems. However, only some had an API. For the rest, the only way was to read their site as a user would.

Similarly, the same story repeated later with hotels and flights on another project. A few principles stayed with me.

One shape for everyone

Each provider had an adapter turning its output into one shared shape: flight, seat, fare class, price. As a result, the rest of the system didn't care whether the data came from a clean API or an HTML page. When a provider got an API, only its adapter changed.

A crawler must notice the page changed

The worst crawler is one that quietly returns nothing when the target site changes. "No flights found" is very different from "I can no longer read this page". The first is an answer; the second is an error someone must hear about.

Therefore each adapter checked its expectations of the page: elements that must exist, date formats, a sensible price range. Wherever the page's shape broke, it raised an alert and kept the suspect result away from the agency.

Be polite

  • Rate limits: a crawler that overloads the target gets blocked quickly.
  • Smart caching: flight prices don't change every second. In fact, a short-lived cache cuts load and speeds up answers.
  • Scheduled instead of on-demand: some data, like flight calendars, could be read ahead of time by scheduled jobs, not while a user waits.

Ask for the price again at the last moment

Search can come from a cache; booking can't. Before anyone's money was taken, price and availability were asked again from the provider itself. As a result, if they had changed, the user found out before paying, not after.

From B2B to B2C

Once that layer was solid, building on it got simple. As a result, we built a white-label B2C version on the same web service, which any agency could run under its own brand. After that came a referral-marketing module with widgets, referral links, commission calculation and settlements.

The main lesson for me is simple. When you connect to an outside system you don't control, keep the connecting code separate and replaceable. Besides, write it so that when it breaks, it says so loudly.

The same "one shape behind many sources" idea worked for payment gateways too, and for a store where WooCommerce is the source of truth. For a polite crawler, the robots.txt standard is a good start.

Comments

Sign in to leave a comment.

Sign in

Loading…

Related posts