Magento to Snowflake

This page provides you with instructions on how to extract data from Magento and load it into Snowflake. (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 an open source content management system for ecommerce web sites. It's known for its flexibility and wide adoption across ecommerce businesses of all sizes.

What is Snowflake?

Snowflake is a cloud-based data warehouse implemented as a managed service. It runs on the Amazon Web Services architecture using EC2 and S3 instances. Snowflake is designed to be fast, flexible, and easy to work with. For instance, for query processing, Snowflake creates virtual warehouses that run on separate compute clusters, so querying one virtual warehouse doesn't slow down the others.

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.

Preparing data for Snowflake

Depending on the structure that you data is in, you may need to prepare it for loading. Take a look at the supported data types for Snowflake and make sure that the data you've got will map neatly to them. If you have a lot of data, you should compress it. Gzip, bzip2, Brotli, Zstandard v0.8 and deflate/raw deflate compression types are all supported.

One important thing to note here is that you don't need to define a schema in advance when loading JSON data into Snowflake. Onward to loading!

Loading data into Snowflake

There is a good reference for this step in the Data Loading Overview section of the Snowflake documentation. If there isn’t much data that you’re trying to load, then you might be able to use the data loading wizard in the Snowflake web UI. Chances are, the limitations on that tool will make it a non-starter as a reliable ETL solution. There two main steps to getting data into Snowflake:

  • Use the PUT command to stage files
  • Use the COPY INTO table command to load prepared data into the awaiting table from the prior step.

For the COPY step, you’ll have the option of copying from your local drive, or from Amazon S3. One of Snowflakes’ slick features lets you to make a virtual warehouse that will power the insertion process.

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

Snowflake is great, but sometimes you need to optimize for different things when you're choosing a data warehouse. Some folks choose to go with Amazon Redshift, Google BigQuery, or PostgreSQL, which are RDBMSes that use similar SQL syntax. If you're interested in seeing the relevant steps for loading data into one of these platforms, check out To Redshift, To BigQuery, 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 Snowflake data warehouse.