GCP Cloud tasks API

x

NFT dev

What just happened?🤔
- "I noticed Shubham get excited about something a couple of weeks back and I'm happy for him but I don't really get it" 😄
- "I understand the issue we were having with the savings pull job + downtime daily, but I don't know how we solved it" 🫤
- "I understood the problem and kinda get parts of the solution" 💡
- "I know it all" 💃
What was wrong?😰
- Savings has a pull job that runs daily in the night. It sends EPB requests to move money from customer's external banks (SEB, Swedbank, etc) to their EPB savings account
- A few months ago, Vilja rate-limited Anyfin with a quota of 800 req/min 🤦🏻‍♂️
- Since we had about 40k reqs to make every night with no real flow control on the number of requests we make to Vilja, we would exhaust the quota => Customers would not see anything in the app during the bg process 😱
What was wrong?😰
What was wrong?😰
😭
😭
😭
😭
😭
😭
😭
😭
😭
😭
😭
😭
Why was it so? 😾
- Originally, the pull mechanism was supported by a pub/sub event 📣
- Pub/Sub is an amazing GCP tool which allows a publisher to broadcast messages to whoever is listening, with no concern about (control over) the rate of firing these messages. Google cloud also does not ensure that each message reaches only a single instance of the subscriber
- For our usecase, some of these features are problematic!
Broadcasts messages to whoever is listening👂
Pub/Sub Topic
savings.pull-triggered
Savings
Service
Hey, I'd like to know when someone says something about this topic
Sure thing, Mate!
Broadcasts messages to whoever is listening👂
Pub/Sub Topic
savings.pull-triggered
Pull script
Yoooo, dropping an event for customer 113244. Send it to whoever 🤷🏻‍♂️

🎁

Broadcasts messages to whoever is listening👂
Pub/Sub Topic
savings.pull-triggered

🎁

Savings
Service
Hey, I've a new event that you should totes check out
Savings
Service
Savings
Service
Savings
Service
Wait, there's more of you? Guess you all can act on this event
Broadcasts messages to whoever is listening👂
- And that, kids, is mainly (aside from actual bugs we wrote) why we had double pulls
- This also rolls into the point: Pub/Sub 
does not ensure that each message reaches only a single instance of the subscriber
No concern about (control over) the rate of firing these messages 🎮
- In Pub/Sub, only the subscribers can control the rate at which they accept messages.
- The topic OR the publisher have no control over how many messages are processed at a time
Savings
Service
I can do just 15 at a time
Savings
Service
I can do just 15 at a time
Savings
Service
I can do just 15 at a time
No concern about (control over) the rate of firing these messages 🎮
- This causes us to hit the rate limit very often when we use Pub/Sub
Okay, so what fixed this?🩹
What is this and what does it offer⁉️
- No control over who's listening in pub/sub => Senders have to explicitly say where to send the message
Message sender
Cloud tasks queue
Hey, can you send this message to https://savings.anyf.in/pull-transactions?
What is this and what does it offer⁉️
- No more double pulls
*
* = Provided we don't have any other bugs
What is this and what does it offer⁉️
- No concern about (control over) the rate of firing these messages in Pub/Sub => Queue controls the task dispatch rate
Cloud tasks queue
Task 4
Task 3
Task 2
Task 1
https://savings.anyf.in/pull-transactions
Hey, move it!
The queue says: Wait for your turn. This guy can only handle 1 at a time
What is this and what does it offer⁉️
- No more downtime while background processes run!
What does the code look like 💻
What does the code look like 💻
With Pub/Sub
With Cloud Tasks
What's next? 📲
- Now that we know (mostly) that background tasks can run without a downtime, we should bring back the transactions sync
- We're processing WAYYYYY more than we should!
We're processing WAYYYYY more than we should!
Total Customers processed
Customers we actually pulled money for
What did I learn from this?👨🏻‍🎓
- Don't try over-fitting a tool if you sense that it's not the right choice.
- It's really fun and fulfilling to try something new.
Bonus if it works 🎉
- You can always reach out to Shubham or someone else in NFT dev to know more
Frågor?

GCP Cloud tasks API

By Shubham Zanwar