🗓️ Live Webinar August 17: How Allbirds solves identity resolution in the warehouse with dbt Labs, Snowflake, and RudderStack

Register Now
By Rudderstack Team

How to load data from Recurly to Redshift

The purpose of this post is to help you define a process or pipeline, for getting your subscription-related data from Recurly and load it into Amazon Redshift for further analysis. We will see how to access and extract your data from Recurly through its API and how to load it into Redshift. This process requires you to write the code to get the data and make sure that this process will run every time new data is generated. Alternatively, in order to load your data from Recurly to Redshift, you can use products like RudderStack that can handle this kind of problem automatically for you.

About Recurly

Recurly is a subscription billing management service. It currently provides enterprise-class subscription management for thousands of businesses worldwide. It offers a trusted, flexible subscription management solutions that help companies to maximize recurring revenues. It is easy to set up, a company can be up and running with Recurly in days instead of months, compared to building your own recurrent subscription service for your product. Regarding subscriptions it offers the following:

  • Plan management. You can create as many plans as you want, define billing cycles and manage upgrades and downgrades.
  • Multi-subscription support. Your customers can have multiple subscriptions running simultaneously.
  • Trials & Setup fees. You can easily set up and configure trials for your product. It is also possible to include setup fees if these are required by your product.
  • Virtual terminal. Recurly provides an easy and intuitive interface to set up subscriptions or process one-time payments over the phone.
  • Add-ons. Add-Ons provide a great deal of versatility for your business. By presenting optional Add-Ons, your subscribers select the plan that is perfectly tailored to suit their needs.

A subscription system like Recurly generates a lot of valuable data related to how your product and company interact with customers, data that you would like to export and analyze to drive your business and your product development. Fortunately, Recurly exposes a rich ecosystem of tools and APIs that you can use to get the most out of their service and have full control over both your data and your integration with their platform.

About Amazon Redshift

Amazon Redshift is one of the most popular data warehousing solutions part of the Amazon Web Services (AWS) ecosystem. It is a petabyte-scale, fully managed data warehouse as a service solution that runs on the cloud. It is SQL-based, and you can communicate with it as you would do with PostgreSQL. You can use the same driver, although it would be better to use the drivers recommended by Amazon. You can connect either through JDBC or ODBC connections.

Extract your data from Recurly

The Recurly API allows applications to interact directly with its platform. In general, Recurly offers the following ways of integrating with their services:

  • Hosted Payment Pages. With this product, merchants can start immediately subscribing to their customers with minimal effort and without requiring significant technical skills.
  • js. A JavaScript library that can be used to integrate the functionality of Recurly into your product securely.
  • API. A Web API that exposes the full functionality of Recurly through its interface for integrating with it programmatically.

From the above three methods, we are interested in the last one as it is the only way that we can use to pull data from the Recurly platform. There’s also a plethora of SDKs so you can interact with the API from your language or framework of choice:

The Recurly API is a RESTful web service. As a RESTful API, interacting with it can also be achieved by using tools like CURL or Postman or Apirise or by using http clients for your favorite language or framework, instead of one of the previously mentioned SDKs. A few suggestions:

Recurly API Authentication

Recurly is using HTTP Basic Authentication using your API Key for credentials. All data are transferred over a secure SSL channel. Below an example using Curl that demonstrates how authentications work for Recurly:

curl -H 'Accept: application/xml' \
-H 'X-Api-Version: 2.1' \
-H 'Content-Type: application/xml; charset=utf-8' \
-u [API Key]: https://[subdomain].recurly.com/v2/accounts

Recurly supports the use of multiple Private API keys, which can be used to integrate third-party services using unique, controlled credentials. With the following limitations:

  • Core & grandfathered Recurly plans are granted 5 private API keys.
  • Professional plan grants 10 API keys.

Rate Limits

By default, new Recurly sites have the following API rate limits:

  • Sandbox sites: 400 requests/min. All requests count towards the rate limit.
  • Production sites: 1,000 requests/min. Only GET requests to count towards the rate limit.

Once your site moves into production mode, Recurly will only rate limit GET requests. New subscriptions, account modifications, and other requests using POST PUT or DELETE methods will not count against your rate limit.

The rate limit is calculated over a sliding 5-minute window. This means a production site could make 4,000 requests within one minute and not hit the rate limit so long as the site made less than 1,000 requests during the prior 4 minutes.

If an API request exceeds the rate limit, the API returns a 429 status code indicating Too Many Requests.

Prepare your Recurly Data for Amazon Redshift

Amazon Redshift is built around industry-standard SQL with added functionality to manage very large datasets and high-performance analysis. So, to load your data into it, you will have to follow its data model, a typical relational database model. The data you extract from your data source should be mapped into tables and columns where you can consider the table as a map to the resource you want to store and columns the resource attributes. Also, each attribute should adhere to the datatypes that are supported by Redshift. Currently, the datatypes that are supported are the following:

  • REAL
  • CHAR
  • DATE

As your data are probably coming in a representation like JSON that supports a much smaller range of data types you have to be really careful about what data you feed into Redshift and make sure that you have mapped your types into one of the datatypes that is supported by Redshift. Designing a Schema for Redshift and mapping the data from your data source to it is a process that you should take seriously as it can both affect the performance of your cluster and the questions that you can answer. It’s always a good idea to have in your mind the best practices that Amazon has published regarding the design of a Redshift database. When you have concluded on the design of your database you need to load your data on one of the data sources that are supported as input by Redshift, these are the following:

Load data from Recurly to Redshift

The first step to load your Recurly data to Redshift is to put them in a source that Redshift can pull it from. As it was mentioned earlier there are three main data sources supported, Amazon S3, Amazon DynamoDB, and Amazon Kinesis Firehose, with Firehose being the most recent addition as a way to insert data into Redshift.

To upload your data to Amazon S3, you will have to use the AWS REST API. As we see again APIs play an important role in both the extraction but also the loading of data into our data warehouse. The first task that you have to perform is to create a bucket. You do that by executing an HTTP PUT on the Amazon AWS REST API endpoints for S3. You can do this by using a tool like CURL or Postman or Apirise. Or use the libraries provided by Amazon for your favorite language. You can find more information by reading the API reference for the Bucket operations on Amazon AWS documentation.

After you have created your bucket you can start sending your data to Amazon S3, using again the same AWS REST API but by using the endpoints for Object operations. As in the Bucket case, you can either access the HTTP endpoints directly or use the library of your preference.

DynamoDB imports data again from S3. It adds another step between S3 and Amazon Redshift so if you don’t need it for other reasons, you can avoid it.

Amazon Kinesis Firehose is the latest addition as a way to insert data into Redshift and offers a real-time streaming approach to data importing. The necessary steps for adding data to Redshift through Kinesis Firehose are the following:

  1. create a delivery stream
  2. add data to the stream

Whenever you add new data to the stream, Kinesis takes care of adding this data to S3 or Redshift, again going through S3, in this case, is redundant if your goal is to move your data to Redshift. The execution of the previous two steps can be performed either through the REST API or through your favorite library just as in the previous two cases. The difference here is that for pushing your data into the stream you’ll be using a Kinesis Agent.

Amazon Redshift supports two methods for loading data into it. The first one is by invoking an INSERT command. You can connect to your Amazon Redshift instance with your client, using either a JDBC or ODBC connection and then you perform an INSERT command for your data.

insert into category_stage values
(12, 'Concerts', 'Comedy', 'All stand-up comedy performances');

The way you invoke the INSERT command is the same as you would do with any other SQL database. For more information, you can check the INSERT examples page on the Amazon Redshift documentation.

Redshift is not designed for INSERT-like operations. On the contrary, the most efficient way of loading data into it is by doing bulk uploads using a COPY command. You can perform a COPY command for data that lives as flat files on S3 or from an Amazon DynamoDB table. When you perform COPY commands, Redshift can read multiple files simultaneously, and it automatically distributes the workload to the cluster nodes and performs the load in parallel. COPY is quite flexible as a command and allows for many different ways of using it, depending on your use case. Performing a COPY on amazon S3 is as simple as the following command:

copy listing
from 's3://mybucket/data/listing/'
credentials 'aws_access_key_id=;aws_secret_access_key=';

For more examples of invoking a COPY command, you can check the COPY examples page on Amazon Redshift documentation. As in the INSERT case, the way to perform the COPY command is by connecting to your Amazon Redshift instance using a JDBC or ODBC connection and then invoke the commands you want using the SQL Reference from Amazon Redshift documentation.

The best way to load data from Reculry to Amazon Redshift and possible alternatives

So far, we just scraped the surface of what can be done with Amazon Redshift and how to load data into it. The way to proceed relies heavily on the data you want to load, from which service they are coming from, and the requirements of your use case. Things can get even more complicated if you want to integrate data coming from different sources. A possible alternative, instead of writing, hosting, and maintaining a flexible data infrastructure, is to use a product like RudderStack that can handle this kind of problem automatically for you.

RudderStack integrates with multiple sources or services like databases, CRM, email campaigns, analytics, and more.

Get Started Image

Get started today

Start building smarter customer data pipelines today with RudderStack. Our solutions engineering team is here to help.

Customer Data Platform for Developers | RudderStack
HIPPA Compliant