Revoke access when a subscription lapses
Call your own API to revoke access when a subscription ends in PostgreSQL, once per subscription. Watch the requests in shadow mode before it goes live.
- PostgreSQL
- Any REST API
- Engineering
- once per subscription
The trigger
One read-only SELECT against PostgreSQL. Rowfire polls it for new rows, and the rule fires once per subscription.
SELECT s.id AS subscription_id,
s.account_id,
a.name AS account,
s.plan,
s.ended_at
FROM subscriptions s
JOIN accounts a ON a.id = s.account_id
WHERE s.status = 'ended'
AND s.ended_at IS NOT NULLThe clock is ended_at and the key is subscription_id, so each lapse is
handled once, even if the row is touched again later. Table and column names
are a sketch; adapt them to your schema.
Calling your own API
Any REST API can be an integration: a base URL, an auth scheme and a request per action, configured as data rather than code. A revoke action might render:
POST /internal/accounts/{{ account_id }}/revoke
{"reason": "subscription_ended", "subscription_id": "{{ subscription_id }}", "plan": "{{ plan }}"}
Credentials are encrypted at rest and applied at send time, so the recorded copy of each request never contains a token.
Why shadow first matters here
Unlike a Slack message, this action changes something. Run it in shadow, compare the recorded requests with the lapses you expect, and keep the kill switch in mind: it stops every rule at once. For a softer touch before access ends, see declined cards to Slack and Zendesk.
Questions
Is this fast enough for access control?
Triggers are polled, within a minute by default. That suits ending access after a subscription lapses. It is not meant for anything that must happen inside the request that caused it.
How do we know it won't revoke the wrong accounts?
New rules run in shadow: every request is rendered and recorded but not sent. Check the recorded calls against the accounts you expect, then promote the rule to live.