Monzo was hitting my webhook API multiple times in quick succession

I’ve been using the Monzo banking API for several years. The web hook is great, it means all my Monzo transactions are received by a small API I wrote and populate my cashflow, I love it :slight_smile:

There was a period of a few months where I noticed the same transaction would be logged by my API several times. This was very strange as my API checks the database to see if the Monzo transaction already exists before inserting it (if the transaction already exists it would be updated).

I then realised what was happening: Monzo was hitting my API several times in very quick succession. So my API hadn’t finished processing the first hit before being hit again with the same transaction, resulting in a sort of race condition.

I applied a quick fix to this: I made the monzoTransactionID field in my database unique, so if Monzo hits my API too quickly with the same transaction the API responds with an error to the duplicate hits.

I’ve now looked at the code behind my API again and I can see that there is way too much logic in there, it not only checks if the transaction already exists, but also the category, merchant etc in order to create good relational data. I should probably rewrite the code, maybe putting the transactions into a queue first.

I’m wondering if anyone else has had this issue, and how have you got around it ?

1 Like

Seems to be a known issue