How to load data from Recurly to SQL Data Warehouse
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 to their customers with minimal effort and without requiring significant technical skills.
- js. A JavaScript library that can be used to securely integrate the functionality of Recurly in your product.
- 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:
- PHP (official)
- Ruby (official)
- Python (official)
- .NET (official)
- Recurly SDK iOS from Cocoadocs (official)
- Android (official)
- Java (unofficial)
- Go (unofficial)
- Node.js (unofficial)
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:
SH
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.
- The 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 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.
Load Data from Recurly to SQL Data Warehouse
SQL Data Warehouse support numerous options for loading data, such us:
- PolyBase
- Azure Data Factory
- BCP command-line utility
- SQL Server integration services
As we are interested in loading data from online services by using their exposed HTTP APIs, we are not going to consider the usage of BCP command-line utility or SQL server integration in this guide. We’ll consider the case of loading our data as Azure storage Blobs and then use PolyBase to load the data into SQL Data Warehouse.
Accessing these services happens through HTTP APIs, as we see again APIs play an important role in both the extraction but also the loading of data into our data warehouse. You can access these APIs by using a tool like CURL, Postman or Apirise. Or use the libraries provided by Microsoft for your favorite language. Before you actually upload any data you have to create a container which is something similar to a concept to the Amazon AWS Bucket, creating a container is a straightforward operation and you can do it by following the instructions found on the Blog storage documentation from Microsoft. As an example, the following code can create a container in Node.js.
JAVASCRIPT
blobSvc.createContainerIfNotExists('mycontainer', function(error, result, response){if(!error){// Container exists and allows// anonymous read access to blob// content and metadata within this container}});
After the creation of the container you can start uploading data to it by using again the given SDK of your choice in a similar fashion:
JAVASCRIPT
blobSvc.createBlockBlobFromLocalFile('mycontainer', 'myblob', 'test.txt', function(error, result, response){if(!error){// file uploaded}});
When you are done putting your data into Azure Blobs you are ready to load it into SQL Data Warehouse using PolyBase. To do that you should follow the directions in the Load with PolyBase documentation. In summary the required steps to do it, are the following:
- create a database master key
- create a database scoped credentials
- create an external file format
- create an external data source
PolyBase’s ability to transparently parallelize loads from Azure Blob Storage will make it the fastest tool for loading data. After configuring PolyBase, you can load data directly into your SQL Data Warehouse by simply creating an external table that points to your data in storage and then mapping that data to a new table within SQL Data Warehouse.
Of course, you will need to establish a recurrent process that will extract any newly created data from your service, load them in the form of Azure Blobs and initiate the PolyBase process for importing the data again into SQL Data Warehouse. One way of doing this is by using the Azure Data Factory service. In case you would like to follow this path you can read some good documentation on how to move data to and from Azure SQL Warehouse using Azure Data Factory.
The best way to load data from Reculry to SQL Data Warehouse and possible alternatives
So far we just scraped the surface of what can be done with Microsoft Azure SQL Data Warehouse 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 with multiple sources or services like databases, CRM, email campaigns, analytics, and more.