Mailchimp to Snowflake

This page provides you with instructions on how to extract data from Mailchimp 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.)

About Snowflake

Snowflake is a data warehouse solution that is entirely cloud based. It's a managed service. If you don't want to deal with hardware, software, or upkeep for a data warehouse you're going to love Snowflake. It runs on the wicked fast Amazon Web Services architecture using EC2 and S3 instances. Snowflake is designed to be flexible and easy to work with where other relational databases are not. One example of this is the query execution. Snowflake creates virtual warehouses where query processing takes place. These virtual warehouses run on separate compute clusters, so querying one of these virtual warehouses doesn't slow down the others. If you have ever had to wait for a query to complete, you know the value of speed and efficiency for query processing.

Getting data out of Mailchimp

In order to get your MailChimp data into your data warehouse, you have to start by extracting it from MailChimp’s servers. You can do this using the MailChimp API, which is available to all MailChimp customers. Full API documentation can be accessed at this link

The tricky thing about Mailchimp is that it generates a LOT of data. Anytime you send an email or someone opens and reads one, you are generating data and that can add up very quickly. Depending on your needs, you may want to use Webhooks technology in order to continuously receive streaming updates of these events as they happen. Unfortunately, that means you’ll also need to build code on your end to receive this streaming data.

Mailchimp also offers a more durable API for syncing campaign information and stats that may be more what you’re looking for. Check out the docs through the lens of your use case to make the right call for you.

Sample Mailchimp data

The Mailchimp API returns JSON-formatted data. Below is an example of the kind of response you might see when querying the accounts endpoint.

HTTP/1.1 200 OK
{
 "account_id": "8d3a3db4d97663a9074efcc16",
 "account_name": "Freddie's Jokes",
 "contact": {
   "company": "Freddie's Jokes",
   "addr1": "675 Ponce De Leon Ave NE",
   "addr2": "Suite 5000",
   "city": "Atlanta",
   "state": "GA",
   "zip": "30308",
   "country": "US"
 },
 "last_login": "2015-09-15 14:25:37",
 "total_subscribers": 413,
 "_links": [
   {
     "rel": "self",
     "href": "https://usX.api.mailchimp.com/3.0/",
     "method": "GET",
     "targetSchema": "https://api.mailchimp.com/schema/3.0/Root.json"
   },
   {
     "rel": "lists",
     "href": "https://usX.api.mailchimp.com/3.0/lists",
     "method": "GET",
     "targetSchema": "https://api.mailchimp.com/schema/3.0/Lists/Collection.json",
     "schema": "https://api.mailchimp.com/schema/3.0/CollectionLinks/Lists.json"
   },
   {
     "rel": "reports",
     "href": "https://usX.api.mailchimp.com/3.0/reports",
     "method": "GET",
     "targetSchema": "https://api.mailchimp.com/schema/3.0/Reports/Collection.json",
     "schema": "https://api.mailchimp.com/schema/3.0/CollectionLinks/Reports.json"
   },
   {
     "rel": "conversations",
     "href": "https://usX.api.mailchimp.com/3.0/conversations",
     "method": "GET",
     "targetSchema": "https://api.mailchimp.com/schema/3.0/Conversations/Collection.json",
     "schema": "https://api.mailchimp.com/schema/3.0/CollectionLinks/Conversations.json"
   },
   {
     "rel": "campaigns",
     "href": "https://usX.api.mailchimp.com/3.0/campaigns",
     "method": "GET",
     "targetSchema": "https://api.mailchimp.com/schema/3.0/Campaigns/Collection.json",
     "schema": "https://api.mailchimp.com/schema/3.0/CollectionLinks/Campaigns.json"
   },
   {
     "rel": "automations",
     "href": "https://usX.api.mailchimp.com/3.0/automations",
     "method": "GET",
     "targetSchema": "https://api.mailchimp.com/schema/3.0/Automations/Collection.json",
     "schema": "https://api.mailchimp.com/schema/3.0/CollectionLinks/Automations.json"
   },
   {
     "rel": "templates",
     "href": "https://usX.api.mailchimp.com/3.0/templates",
     "method": "GET",
     "targetSchema": "https://api.mailchimp.com/schema/3.0/Templates/Collection.json",
     "schema": "https://api.mailchimp.com/schema/3.0/CollectionLinks/Templates.json"
   },
   {
     "rel": "file-manager",
     "href": "https://usX.api.mailchimp.com/3.0/file-manager",
     "method": "GET",
     "targetSchema": "https://api.mailchimp.com/schema/3.0/FileManager/Namespace.json"
   },
   {
     "rel": "authorized-apps",
     "href": "https://usX.api.mailchimp.com/3.0/authorized-apps",
     "method": "GET",
     "targetSchema": "https://api.mailchimp.com/schema/3.0/AuthorizedApps/Collection.json"
   }
 ]
}

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 Mailchimp data up to date

By now you're definitely thinking that the end is near right? There is still work to be done. After all, what is the point of making a script that moves data to your data warehouse once? What happens tomorrow when you have a thousand new transactions, or heck, just one?

The key is to build your script in such a way that it can also identify incremental updates to your data. Thankfully, MailChimp’s API results include fields like created_at that allow you to quickly identify records that are new since your last update (or since the newest record you’ve copied into Redshift). You can set your script up as a cron job or continuous loop to keep pulling down new data as it appears.

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 Mailchimp data via the API, structuring it in a way that is optimized for analysis, and inserting that data into your Snowflake data warehouse.