Giter Site home page Giter Site logo

Comments (1)

kamilkisiela avatar kamilkisiela commented on May 22, 2024

Types of emails we need (as of today)

  • Notify org's owner about reaching 90% of the usage limit
  • Notify org's owner about the rate-limit
  • Notify org's owner about the upcoming end of the trial period

Scheduling

I think the "upcoming end of the trial" email could be sent from Stripe directly.

The first two emails (related to usage limits) should be scheduled by either the usage-estimator or the rate-limit service but only if the email hasn't been scheduled yet (within the billing period).

Instead of holding the state (email sent or not yet) in Postgres, the email service could use BullMQ (Redis) with specific job names (rate-limit-org{id}-period{currentPeriod}).
The problem with this approach is the persistence of data (Redis is in-memory) that can cause sending multiple emails. The data is gone when the pod is restarted (version upgrade of Redis or K8s). We would have to use external storage.

Rendering emails

Who should create an email body?
Should it be done in the email service (data + template id) or by the consumer (email prepared by rate-limit service)?
Doing it in the email service means it is aware of all the email templates but on the other hand, who cares? Making everything isolated just to make it isolated makes no sense.

How should the body be created?
We need simple HTML with a few CSS rules.

Maybe a type-safe template?

const email = getEmail('template-name-here');
//                           ^ type-safe: to make sure the template exists
const body = email.body({ ...props });
//                         ^ type-safe: to make sure we pass all the data
const title = email.title({ ...props });
//                           ^ type-safe: to make sure we pass all the data

Maybe a combination of TypeScript and mjml? It has an online editor and a big community and a big list of features.

We could have an "email client" that is fully type-safe, holds all the email templates, and connects to the email service nicely. Keeping the emails in a single place is fine. We could use tRPC here.

emailService.send({
  template: 'rate-limit',
  address: '[email protected]',
  input: {
    org: { name: 'GraphQL Hive' },
    limit: 1_000_000,
    used: 1_100_000,
  }
});

from graphql-hive.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.