3

I am working on a SaaS project that will have a trial when the trial is ending I get a webhook notification when 3 days are remaining. I do some stuff with this and one of the things is I update user.company.stripe.trialEnd to the value Stripe tells me for the ending time.

When a trial ends I'd like some cron/Lambda job that runs once per hour and updates the correct things for when a trial ends.

Currently, when a payment fails a webhook takes that and marks the user unable to log in properly (redirects to billing) and forces them to stay on that page until they pay so as to prevent them from using the site.

Also when this happens the webhook service sends API calls to my serviceA and serviceB which then do some things like disabling certain things that cost me extra and then updates their user with some new values.

I want pretty much the exact same thing to happen when a trial has ended.

My question comes in how to do this? Currently, I have two thoughts on options,

  1. have the lambda call my Consul cluster and then send API calls to the correct services

  2. move the logic I need into a Lambda (and remove from the two services) which would then work off a SQS queue where my webhook service would publish a message to the queue and my Lambda would do the work there and only run when needed.

Issues I see with the options...

    • I currently have no clue how to connect Lambda to Consul to get the right IP/port for what I need

    • My other services are running inside Kubernetes

    • Introduces an extra point of failure

    • Potentially increases cost

    • Means I now have to keep my data (mongoose) models up to date in multiple git repos and services which I can see being an issue as I scale.

An option I came up with after typing this was using a Kubernetes cron job that would be in the same cluster and run Node.js like the rest of my microservices. This seems like a simple option but not sure how good it is from a design perspective.

2
  • Which option provides the best benefit/cost ratio? Commented Aug 2, 2019 at 22:12
  • @RobertHarvey I'm not really sure, this is for a new project so nothing really to compare against. As for server costs, the lambda route would be the cheapest but then I get into the issues of connecting to my other services properly which was the thing that initially prompted me to want to post looking for help.
    – joshk132
    Commented Aug 2, 2019 at 23:29

1 Answer 1

0

I figured since no one has responded with an answer for this question I would come back and give a bit of insight into what solution I ended up going with.

I now have a set of Lambdas that work based off queues where a initiation lambda runs and finds all the users needed based off criteria and then puts them into a SNS topic.

I then go with a fan out method and have it so it will write back to my DB when each thing is done and will include a time stamp on it. I then have a Lambda that runs 5 minutes after the inital one which goes back and checks to make sure all are done according to what the inital one said for the fan out lambdas to do.

This last lambda will then either put into a time series database that they completed or not, and if not it will fire off an alert to me which indicates something went wrong along the way so I can check into it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.