Magento to BigQuery

This page provides you with instructions on how to extract data from Magento and load it into Google BigQuery. (If this manual process sounds onerous, check out Stitch, which can do all the heavy lifting for you in just a few clicks.)

What is Magento?

Magento is a wildly popular open-source content management system for e-commerce web sites. It is developed in PHP and is known for its flexibility and wide adoption across e-commerce businesses of all sizes.

What is Google BigQuery?

Google BigQuery is a data warehouse that delivers super-fast results from SQL queries, which it accomplishes using a powerful engine dubbed Dremel. With BigQuery, there's no spinning up (and down) clusters of machines as you work with your data. With all of that said, it's clear why some claim that BigQuery prioritizes querying over administration. It's super fast, and that's the reason why most folks use it.

Getting data out of Magento

There are two ways for you to extract data from Magento: the API and pulling directly from the underlying database.

Magento’s API is unique relative to traditional SaaS APIs because Magento is self-hosted to begin with. While the API provides a helpful interface for extracting structured data, you do have lower-level access available if you decide it’s more appropriate.

Depending on the information you want to extract, the Magento API could be a good fit. You can check out the API Docs to learn more. Be warned, however, that the many historical versions of Magento could lead to inconsistent compatibility with different API calls. In most recent version, Magento offers both REST and SOAP versions of their API.

If you’d prefer to dig in at a lower level, you can actually run queries directly on the underlying database that is powering your Magento instance. (Hitting the API is really just doing this via a layer of abstraction.) If you go this route, it will be very helpful to familiarize yourself with the Magento database structure, which you can find here.

Preparing Magento data

Your Magento data will need to be structured into a schema that can be inserted into your destination database. If you don’t mind dealing with the default Magento DB structure in your analytical environment, this simply means recreating the tables and fields that you pulled from your Magento API. You can refer to the API docs or use the information_schema tables in those databases to understand these formats.

Loading data into Google BigQuery

Google Cloud Platform offers a helpful guide for loading data into BigQuery. You can use the bq command-line tool to upload the files to your awaiting datasets, adding the correct schema and data type information along the way. The bq load command is your friend here. You can find the syntax in the bq command-line tool quickstart guide. Iterate through this process as many times as it takes to load all of your tables into BigQuery.

Keeping Magento data up to date

You've built a script that pulls data from Magento and loads it into your data warehouse, but that’s only half the battle. What happens when you have new data?

The key is to build your script in such a way that it can also identify incremental updates to your data. Much of Magento's data includes fields like created_at or auto-incrementing IDs that allow you to quickly identify records that are new since your last update. You can set your script up as a cron job or continuous loop to keep pulling down new data as it appears.

Other data warehouse options

BigQuery is really great, but sometimes you need to optimize for different things when you're choosing a data warehouse. Some folks choose to go with Postgres or Redshift, which are two RDBMSes that use similar SQL syntax. If you're interested in seeing the relevant steps for loading this data into Postgres or Redshift, check out To Redshift and To Postgres.

Easier and faster alternatives

If all this sounds a bit overwhelming, don’t be alarmed. If you have all the skills necessary to go through this process, chances are building and maintaining a script like this isn’t a very high-leverage use of your time.

Thankfully, products like Stitch were built to solve this problem automatically. With just a few clicks, Stitch starts extracting your Magento data via the API, structuring it in a way that is optimized for analysis, and inserting that data into your Google BigQuery data warehouse.