Urgent.News

What's breaking now, across thousands of outlets.

Tech

Building an open source subscription backend

My first attempt to add subscriptions to my app failed, so I built SubTru. SubTru is an open source, self-hostable API that processes subscription events from Stripe, the Apple App Store, and Google Play. Your app can then call SubTru's GET /access endpoint to fetch any user's subscription status. Below, I discuss some of the challenges I faced and the design decisions I made along the way. It…

In the story of creating an open source subscription backend called SubTru, the author initially struggled with building a robust system to handle subscriptions from various platforms. SubTru is an open source, self-hostable API that processes subscription events from Stripe, the Apple App Store, and Google Play, allowing apps to check user subscription status via a GET /access endpoint.

The author learned early on that subscription handling is complicated, with issues such as multiple events for a single change, events arriving out of order, and varying payload structures and verification mechanisms from each provider.

To address these challenges, the author established four main design requirements for the subscription handling infrastructure: processing events from Stripe, Apple App Store, and Google Play, storing subscription records in a database, making subscription info available to the app for product access decisions, and ensuring easy self-hosting for developers. These requirements guided the decision-making process for the architecture, event processing, database selection, and deployment method.

The service was designed as an API with HTTP POST /webhooks endpoints for each provider to send events and a GET /access endpoint for apps to fetch user subscription data. The author chose to use a single service for receiving and processing events due to considerations around failure isolation, recovery, scalability, and deployment simplicity.

The choice of database was less critical, as both relational and NoSQL options could be used; Postgres was selected for its relational nature and wide adoption in the open source community.

The author decided to use containerized services on long-lived machines for deployment, opting for a Docker image that can be easily deployed on various hosting platforms. SQL migration scripts for setting up the Postgres database are also provided. Once the service is deployed and configured, apps can call the GET /access endpoint to retrieve user subscription status, enabling features access based on subscription data.

An example of the GET /access response includes entitlements and access information. The goal of SubTru is to simplify subscription handling for developers and contribute to the open source community through the Apache 2.0 license.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Security updates for Tuesday

Security updates have been issued by AlmaLinux (curl, dpdk, glibc, kernel, nodejs-nodemon, nodejs22, nodejs24, nodejs:18, nodejs:22, patch, qt5, qt5-qtdeclarative, ruby, ruby4.0, ruby:3.3, ruby:4.0…

More from Tuesday 10 November →