At times it felt you could pick a rock and throw it at the Jira board and anything you hit was a problem (and now a broken monitor on top of that 😊 ). Jokes aside, let’s take a very good example of problems you face when joining several headless systems: URLs and routing.
In a sense commercetools and Contentful are two databases containing items. commercetools contains for example Products (t-shirts/bikes/coffee cups or whatnot) and Contentful Pages (Category Page, Campaign Page, Start Page, Coffee cup Brand X Page etc). The items need to form a part of the URL so you can navigate to that item, this is in technical terms called the slug. www.example.com/category-x or www.example.com/category-x/coffe-cup the red part here being the slug. Neither commercetools nor Contentful will solve the actual routing for you, you need to build this yourself.
In a simplified scenario you would build a routing component that worked like this: when the browser asks for a specific URL you parse out the slug and send that request on to commercetools and then Contentful and sort out if any of them has that item and then you fetch the item from the correct source and show it. Easy peasy right?
There are actually several problems layered here;
- Let’s say Category X suddenly is named Category Y (a very common scenario). You would suddenly get a 404 page. Ask your SEO managers what they think of that. Bring earplugs.
- Lookup of a slug in commercetools and Contentful is fast, but still too slow (10 ms – 200 ms is what we have found). This is a very long time to wait, every millisecond counts. We have it down to average 3 ms now in our solution, and we are proud of that.
- Sometimes you don’t just need one slug entry, if you are using a package that contains several other items then you need to fetch each of them to.
We have created a very advanced routing component that actually builds and tracks all URLs in a separate cloud database. We construct objects for packages and pre-index all URLs, change tracking with automatic redirects for when a product changes category etc. We then cache all URLs to all slugs in commercetools and Contentful to enable even better performance.
This also gives us the possibility to sync changes done in commercetools into Contentful. These are separate systems that are not aware of each other, so when creating a category in commercetools an editor in Contentful has no idea that it exists or how to use it. With our solution we are automatically creating categories and updating them in Contentful so that there is always an updated category tree to use for editors when creating content.
This is just one of many things we had to solve. And we have also made sure that the solution ensures performance, allows scaling and thereby really helps the customer in their daily life.
The development is now coming to an end. The security, performance, UAT etc testing is ongoing and go-live for the first customers is very close. And we are onboarding new customers into the team.