How may I load data from Recurly to Redshift for further analysis? 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 from you to write the code to get the data and make sure that this process will run every time new data are generated. Alternatively, in order to load your data from Recurly to Redshift you can use products like Blendo that can handle this kind of problems automatically for you.
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 maximise recurring revenues. It is easy to setup, 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 setup 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 interacts with customers, data that you would like to be able to export and analyse in order 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 which is 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, actually 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 it is possible for merchants to start immediately subscribing their customers with minimal effort and without requiring significant technical skills.
- API. A Web API that exposes the full functionality of Recurly through its interface for integrating with it programatically.
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:
- PHP (official)
- Ruby (official)
- Python (official)
- .NET (official)
- Recurly SDK iOS (official)
- Android (official)
- Java (unofficial)
- Go (unofficial)
- Node.js (unofficial)
Key Takeaway: You can always sent your data to Amazon Redshift with Blendo.
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 favourite language or framework, instead of one of the previously mentioned SDKs. A few suggestions:
- Apache HttpClient for Java
- Spray-client for Scala
- Hyper for Rust
- Ruby rest-client
- Python http-client
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 works 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.
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 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, in order to load your data into it you will have to follow its data model which is 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 attributes of that resource. Also, each attribute should adhere to the datatypes that are supported by Redshift, currently the datatypes that are supported are the following:
- DOUBLE PRECISION
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 datasources 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 favourite 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 into data importing. The necessary steps for adding data to Redshift through Kinesis Firehose are the following:
- create a delivery stream
- add data to the stream
whenever you add new data to the stream, Kinesis takes care of adding these 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 favourite 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.
Key Takeaway: You can always sent your data to Amazon Redshift with Blendo.
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 is able to read multiple files in simultaneously and it automatically distributes the workload to the cluster nodes and performs the load in parallel. As a command COPY is quite flexible 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 on how to invoke a COPY command you can check thepage 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 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 Blendo that can handle this kind of problems automatically for you.
Blendo integrates with multiple sources or services like databases, CRM, email campaigns, analytics and more. Quickly and safely move all your data from Recurly into Amazon Redshift and start generating insights from your data.