Building a Registration Plate Search Tool

By Charlie Groves

When searching individual registration plates, I found that there was almost never a webpage for that specific registration plate. There were always websites that were along the lines of “here is every registration plate that starts with AB12” but you'd have to do additional navigation to get to the page for “AB12 CDE” when that is what you searched in the first place.

Technical Implementation

The DVLA has a Vehicle Enquiry Service API which takes in a number plate and returns a JSON object with the vehicle details. I applied for an API key and got one a few days later. While waiting, I set up a rails codebase to handle database and API requests.

There are no easily accessible databases of registration plates in the UK, so I had to generate possible registration plates and then check if they were valid by calling the API and checking for 200 and 404 responses. If the response was 200, I would save the registration plate to the database. If the response was 404, I would know that the registration plate was not valid and not save it.

This all happens in an EnrichRegistrationPlateJob which runs after creation of a new registration plate. This in combination with a scheduled rake task to generate new registration plates keeps the database growing.

One region can have many registration plates, and are namespaced to the iso country code of the region, e.g. https://searchregistrationplates.com/regions/gb/registration_plates/pn18vfz. This makes sure there are no collisions between registration plates in different regions.

Sitemap Generation Challenge

I wanted an automatically generated sitemap for the website, so I used the sitemap_generator gem to generate a sitemap.xml file. However, the sitemap depends on the database on production and heroku is a read only filesystem.

SitemapGenerator::Sitemap.create do
  add regions_path, priority: 0.7, changefreq: "daily"

  Region.find_each do |region|
    add region_path(region), priority: 0.7, changefreq: "daily"
    add region_registration_plates_path(region), priority: 0.7, changefreq: "daily"
    region.registration_plates.find_each do |registration_plate|
      add region_registration_plate_path(
        region, registration_plate
      ), priority: 0.7, lastmod: registration_plate.updated_at
    end
  end
end

I had to work around this by generating the sitemap.xml file and uploading it to an AWS S3 bucket which has its own complexities. Then I found out that google requires a sitemap to be hosted on the same domain as the website so trying to add the aws bucket link to google search console didn't work. This blog post unstuck me, and I added a redirect from https://searchregistrationplates.com/sitemap/xml.gz to the sitemap.xml file in the bucket.