<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Caleb Rider</title>
    <description>The latest articles on DEV Community by Caleb Rider (@calebrider).</description>
    <link>https://dev.to/calebrider</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4220578%2Fadb8988b-3b07-4cdb-a0cb-0e96726cbc3e.png</url>
      <title>DEV Community: Caleb Rider</title>
      <link>https://dev.to/calebrider</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/calebrider"/>
    <language>en</language>
    <item>
      <title>Designing a Stripe, Apple, and Google Play subscription event handler</title>
      <dc:creator>Caleb Rider</dc:creator>
      <pubDate>Wed, 18 Nov 2026 14:02:00 +0000</pubDate>
      <link>https://dev.to/calebrider/designing-a-stripe-apple-and-google-play-subscription-event-handler-14ng</link>
      <guid>https://dev.to/calebrider/designing-a-stripe-apple-and-google-play-subscription-event-handler-14ng</guid>
      <description>&lt;p&gt;When your user purchases or updates their subscription in your app, Stripe, Apple, or Google Play sends out an event that can be used to update your record of their subscription status. In my previous article, &lt;a href="https://dev.to/calebrider/how-i-added-subscriptions-to-my-app-18od"&gt;Building an open source subscription backend&lt;/a&gt;, I gave a high-level overview of building an open source, self-hostable service known as &lt;a href="https://subtru.com/?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=designing-event-handler"&gt;SubTru&lt;/a&gt;. SubTru processes the subscription events sent from Stripe, the Apple App Store, and Google Play and makes your users' subscription statuses available to your web or mobile app through a GET /access endpoint. In this article, I'll dive deeper into some of the design decisions I made when building SubTru.&lt;/p&gt;

&lt;h2&gt;
  
  
  System requirements
&lt;/h2&gt;

&lt;p&gt;Before jumping into design decisions, it helps to define the system requirements. In the case of SubTru, I wanted a service that could:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Receive subscription events from Stripe, the Apple App Store, and Google Play&lt;/li&gt;
&lt;li&gt;Process those events and write subscription records to a database&lt;/li&gt;
&lt;li&gt;Make user subscription info available to an app for product access decisions&lt;/li&gt;
&lt;li&gt;Be easily self-hostable so it could be used by other developers&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Designing the system
&lt;/h2&gt;

&lt;h3&gt;
  
  
  The API
&lt;/h3&gt;

&lt;p&gt;I wanted this system to work with the three main providers (Stripe, the Apple App Store, and Google Play). Considering the requirements, it made sense to build part of this service as an API so it could both receive subscription events from these providers and make user subscription statuses available to your app through an HTTP endpoint. Here is a high-level overview of that design:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwctuhfzqg9cyjnv5sxmf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwctuhfzqg9cyjnv5sxmf.png" alt="Stripe, Apple, and Google Play send subscription events to SubTru, and an app fetches user subscription access through the SubTru API." width="800" height="336"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The processor
&lt;/h3&gt;

&lt;p&gt;After our system receives a subscription event, the next step would be to process it. This is where things started to get more interesting. Processing an event involves verifying the event actually came from Stripe, Apple, or Google Play, extracting the subscription data from the event (or fetching the subscription status in Google Play's case), storing the subscription data in a common model, ensuring the event is not a duplicate or stale, and responding back to the provider to indicate whether or not the event was successfully processed. &lt;/p&gt;

&lt;h3&gt;
  
  
  Service split
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Multiple services
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdqfojx4e9elpos14q1hb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdqfojx4e9elpos14q1hb.png" alt="Diagram of an alternative design where a queue and a worker process subscription events after the SubTru API receives them." width="800" height="567"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A very sensible architecture for this type of system would be to use a queue and split receiving and processing events into separate services. We could have the API receive events (and provide GET /access checks), a queue to hold events that have not yet been processed, and a worker service to handle processing the events at its own pace. If the processor can't process events as fast as the API receives them, a queue can absorb those bursts. This would allow the receiving and processing systems to scale independently. A queue could theoretically improve reliability by allowing us to store an event and process it at some point in the future, but this isn't as useful in our case since providers will redeliver events until we return a 200 response. The main drawback of adding a queue would be the extra complexity around maintenance and deployment. Since ease of self-hosting was a main requirement for this system, I still wanted to consider alternatives.&lt;/p&gt;

&lt;h4&gt;
  
  
  Single service
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzahvede6uf46v6wvujn1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzahvede6uf46v6wvujn1.png" alt="Diagram of SubTru's single-service design, where the SubTru API processes each event as soon as it arrives." width="800" height="477"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To address the drawback of complexity, I wondered if it would make sense to combine receiving and processing events into a single service. In this design, the service would attempt to process the event right after receiving it. This would allow us to deploy everything from a single Docker image, greatly reducing complexity for self-hosters. Another advantage of this approach would be a faster update to a user's subscription status after receiving an event, since it wouldn't have to pass through a queue first. The main drawback of this approach is that coupling multiple systems (receiving requests, processing events, and providing access checks) means a performance bottleneck in one system could degrade performance in another since they could potentially be competing for the same resources like API or database CPU, memory, and connections. For example, heavy traffic on the GET /access endpoint could pull resources and connections that might slow down or prevent events from being received or processed. This can be mitigated by caching the response to reduce the number of calls and improving performance of the GET request itself. On the flip side, a burst in provider events could slow down access checks. Rate limiting or creating a smaller connection pool for incoming events could help with this. Another potential concern with this design is the lack of failure isolation. For example, a crash when processing a webhook event could also cause a separate part of the system (like access checks) to fail (that's another reason why caching access responses from your app is a good idea). Running multiple instances of the server is an easy way to keep the overall system resilient and mitigate problems if one instance goes down.&lt;/p&gt;

&lt;h4&gt;
  
  
  Middle ground
&lt;/h4&gt;

&lt;p&gt;There are plenty of other designs that land somewhere between the examples I gave above. For example, we could keep receiving and processing events together and run the GET /access checks on a separate deployment. We could do that with or without a queue. The queue could be a Postgres table or a service like SQS. I'm open to considering all designs, but until a need arises, I prefer to keep things as simple as possible. At the time of writing this, SubTru is using the single-service design, since it keeps things simpler, and no major performance concerns have been identified at the current scale. Performance testing the system would be a great next step to identify how excessive load in one area might slow things down in another. This performance data would be worth analyzing before adding complexity to the system unnecessarily.&lt;/p&gt;

&lt;h3&gt;
  
  
  Database
&lt;/h3&gt;

&lt;p&gt;The type of database in this system matters a lot less, since we just need the ability to store and read data. A NoSQL database could have worked perfectly fine, but I decided to use Postgres because a lot of the data we store is relational in nature. Postgres is also widely adopted by the open source community, so it felt like a great fit for that reason as well.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deployment
&lt;/h3&gt;

&lt;p&gt;Self-hosting SubTru only requires you to deploy two things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A Postgres DB&lt;/li&gt;
&lt;li&gt;The SubTru service&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Deploying the Postgres DB
&lt;/h4&gt;

&lt;p&gt;The SubTru service needs a Postgres database to work, so it's best to set this up first. Once you've created your database, you can run the &lt;a href="https://github.com/subtru/subtru/tree/main/db/migrations" rel="noopener noreferrer"&gt;DB migration scripts&lt;/a&gt; in the GitHub repo to create all the necessary tables.&lt;/p&gt;

&lt;h4&gt;
  
  
  Deploying the SubTru service
&lt;/h4&gt;

&lt;p&gt;The SubTru service can be deployed by building the image from the &lt;a href="https://github.com/subtru/subtru/blob/main/Dockerfile" rel="noopener noreferrer"&gt;Dockerfile&lt;/a&gt; in the GitHub repo and then running it as a container wherever you prefer, as long as it can connect to your database and has a public HTTPS URL to receive provider events. You'll also need to set some secrets documented in &lt;a href="https://github.com/subtru/subtru#readme" rel="noopener noreferrer"&gt;the README&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sequence diagrams
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Stripe / Apple
&lt;/h3&gt;

&lt;p&gt;Stripe and Apple webhook events both follow a very similar pattern for how they are processed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fldn2dvrebekibm21ho60.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fldn2dvrebekibm21ho60.png" alt="Sequence diagram of how SubTru processes a Stripe or Apple webhook event." width="800" height="1077"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Google
&lt;/h3&gt;

&lt;p&gt;Google Play sends real-time developer notifications (RTDNs) through Pub/Sub, and requires purchase acknowledgement through the Google Play Developer API.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6h7zk8em2iynaj86zk97.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6h7zk8em2iynaj86zk97.png" alt="Sequence diagram of how SubTru processes a Google Play subscription event." width="800" height="924"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Open source GitHub repo
&lt;/h2&gt;

&lt;p&gt;SubTru is open source under the Apache 2.0 license, and all contributions are welcome! There is also a managed SubTru Cloud offering with a dashboard if you would prefer not to self-host. Here's a &lt;a href="https://subtru.com/?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=designing-event-handler"&gt;link to the website&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Please consider &lt;a href="https://github.com/subtru/subtru" rel="noopener noreferrer"&gt;giving SubTru a star on GitHub&lt;/a&gt;. I would really appreciate it!&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>architecture</category>
      <category>systemdesign</category>
      <category>eventdriven</category>
    </item>
    <item>
      <title>Building an open source subscription backend</title>
      <dc:creator>Caleb Rider</dc:creator>
      <pubDate>Tue, 10 Nov 2026 14:02:00 +0000</pubDate>
      <link>https://dev.to/calebrider/how-i-added-subscriptions-to-my-app-18od</link>
      <guid>https://dev.to/calebrider/how-i-added-subscriptions-to-my-app-18od</guid>
      <description>&lt;p&gt;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 &lt;code&gt;GET /access&lt;/code&gt; 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.&lt;/p&gt;

&lt;h2&gt;
  
  
  It started with disaster
&lt;/h2&gt;

&lt;p&gt;I had no idea how challenging adding subscriptions to an app could be. My first attempt at this was a disaster. I had spent months writing the code to handle my users' subscriptions, but all it took was one small misconfiguration for things to break. Long story short, my logic didn't update my customer's subscription status after they made a purchase. I was able to quickly fix the problem, but I felt horrible that I had failed my customer. I felt so bad about the situation, that I vowed to build the most bulletproof subscription handling infrastructure possible and make it open source, so this wouldn't have to happen to anyone else.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is subscription handling?
&lt;/h2&gt;

&lt;p&gt;Subscription handling is complicated. Providers like Stripe, the Apple App Store and Google Play send out events (webhooks or real-time developer notifications in Google's case) whenever your users purchase or change their subscriptions. Those events need to be processed to create and maintain an accurate record of your users' subscriptions. It sounds simple enough on the surface, but here are a few challenges I faced:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Providers often send multiple events for a single subscription change.&lt;/li&gt;
&lt;li&gt;Events sometimes arrive out of order or late.&lt;/li&gt;
&lt;li&gt;Provider events need to be verified before they are trusted.&lt;/li&gt;
&lt;li&gt;Each provider sends a different payload structure and has different verification mechanisms, so the complexity is multiplied by each provider you're using.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Building a subscription service
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Design requirements
&lt;/h3&gt;

&lt;p&gt;There were four main requirements I had in mind for the subscription handling infrastructure I wanted to build.&lt;/p&gt;

&lt;p&gt;I wanted something that could:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Receive subscription events from Stripe, the Apple App Store, and Google Play&lt;/li&gt;
&lt;li&gt;Process those events and write to a database (to maintain subscription records)&lt;/li&gt;
&lt;li&gt;Make my users' subscription info available to my app for product access decisions&lt;/li&gt;
&lt;li&gt;Be easily self-hostable so it could be used by other developers&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These requirements helped me narrow down the possible designs for the infrastructure, but even still, I could have built things in a variety of ways without any of them being "wrong". With most system design problems, they are nuanced and come down to the advantages and tradeoffs unique to your situation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Design decisions
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Architecture
&lt;/h4&gt;

&lt;p&gt;Since this service would need to receive subscription events from providers and also make user subscription data available to external apps, it made sense to design part of it as an API. I added an HTTP &lt;code&gt;POST /webhooks&lt;/code&gt; endpoint for each provider to send events to, and a &lt;code&gt;GET /access&lt;/code&gt; endpoint for apps to fetch user subscription access data. This service would also need to process those provider events and store user subscription data somewhere. Trying to pick the "right" design for event processing was challenging because there were so many ways to combine or split functionality between different services. After weighing the pros and cons around things like failure isolation, failure recovery, scalability, and deployment simplicity, I decided to use a single service to receive and process events. I've considered adding a queue for incoming events so they can be processed separately from when they are received, but there isn't a clear need for that at the moment since the system isn't bottlenecked, and providers can resend events that failed to process. The current approach also has much less complexity for deployment and maintainability.&lt;/p&gt;

&lt;h4&gt;
  
  
  Database
&lt;/h4&gt;

&lt;p&gt;The database decision wasn't as crucial. Since the service just needs a place to store and read data, both a relational or NoSQL DB could have been used here. I decided to go with Postgres since a lot of the data we store is relational in nature, and Postgres is widely adopted by the open source community.&lt;/p&gt;

&lt;h4&gt;
  
  
  Deployment
&lt;/h4&gt;

&lt;p&gt;I try to use serverless functions when they make sense, because I like that they eliminate idle compute costs, but they also have some drawbacks like cold starts, setup complexity, and less support outside AWS, Azure, or Google Cloud. For those reasons, and given our requirements, I figured a containerized service on a long-lived machine made more sense. I added a Dockerfile in the &lt;a href="https://github.com/subtru/subtru" rel="noopener noreferrer"&gt;GitHub repo&lt;/a&gt; so self-hosters can easily deploy the Docker image to their hosting platform of choice. It also doesn't stop self-hosters from deploying to serverless container platforms if they prefer. I've also provided SQL migration scripts in the repo so self-hosters can quickly set up their Postgres database.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding subscriptions to an app
&lt;/h2&gt;

&lt;p&gt;Now, whenever I need to add subscription handling to an app, I don't have to spend months rewriting everything from scratch. All I have to do is deploy the service from the Docker image, run the migration scripts to set up the database, and configure my subscription providers (Stripe, the Apple App Store, and/or Google Play) to send events to the API. Once that's done, I can call the &lt;code&gt;GET /access&lt;/code&gt; endpoint from my app whenever I need to fetch a user's subscription status.&lt;/p&gt;

&lt;p&gt;Here's an example &lt;code&gt;GET /access&lt;/code&gt; response:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"entitlements"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"productId"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"pro_subscription"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"hasAccess"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"accessReason"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"active_subscription"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"accessEndsAt"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2026-12-25T12:43:36.111+00:00"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;My app then uses the &lt;code&gt;productId&lt;/code&gt; and &lt;code&gt;hasAccess&lt;/code&gt; values to decide what features my user has access to. I can optionally cache the customer's subscription status for a duration so I don't have to make repeated calls to the API.&lt;/p&gt;

&lt;h2&gt;
  
  
  Learn more
&lt;/h2&gt;

&lt;p&gt;This project is called SubTru. Here's a &lt;a href="https://subtru.com/?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=add-subscriptions-to-app"&gt;link to the homepage&lt;/a&gt; if you want to learn more. SubTru is completely open source under the Apache 2.0 license, and all contributions are greatly appreciated. There is also a managed, SubTru Cloud offering with a dashboard if you would rather not self-host.&lt;/p&gt;

&lt;p&gt;Thank you so much for your time. I know it's valuable, so I don't take it for granted. Let me know what you think about SubTru so I can learn what's going right and what could be better!&lt;/p&gt;

&lt;p&gt;Please consider &lt;a href="https://github.com/subtru/subtru" rel="noopener noreferrer"&gt;giving SubTru a star on GitHub&lt;/a&gt;. It would mean the world to me.&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>webdev</category>
      <category>learning</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
