Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: initial spike on referrals service #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

travis
Copy link
Member

@travis travis commented Nov 8, 2024

extracted from original implementation in storacha/console#142

This is a very simple REST service built as a Cloudflare worker. I've extracted it from its original implementation because I need to to be a scheduler as well, and that isn't well supported by the next-on-pages deployment style we're using in Next.js.

Users can create "refcodes" by email, look up "refcodes" and "referredby" by email and look up "referrals" by refcode. There is no authorization - this allows the service to work for unauthenticated users, but does mean that anyone can look up refcodes, referrals and referredBy for any email address - we only ever leak lists of refcodes and metadata about them, so I don't think this is too serious a leak, and some level of anonymous interaction is required to meet product requirements, but I do think we should move some of this into an authenticated context (ie, behind UCAN invocations) if we decide to keep scaling this functionality out.

Referral System Database Design

Two tables are used: users and referrals. users is used to store refcodes for users (identified by email address). referrals is used to record the refcode used by a user (identified by email address) during signup. Separate tables are used to avoid mutating rows in the database - a simple, immutable system is generally easier to maintain and reason about and while immutability of database tables isn't a hard requirement, it is a property this design strives to maintain.

Operational Notes

We also introduce a set of scripts prefixed with db:local that make it relatively simple to maintain a local D1 database for development.

extracted from original implementation in storacha/console#142
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant