FreeAgent does't cope well with parallel requests

Hi

Part of our app sends invoices via freeagent, we use the API to generate an
invoice and then send it out.

When I was testing this with 100 bill-runs, with the invoices being
generated in a batch size of 10 (so 10 threads running creating invoices),
we noticed that the (sandbox) free agent API occasionally spits back errors
like this :

[FreeAgentException: StatusCode=422,
Response=RestSharp.RestResponse`1[FreeAgent.InvoiceWrapper],
Content={“errors”:[{“message”:“reference has already been used”}]}]

That response is when we’re trying to add a bank transaction explanation
for the invoice we’ve just added.

If we throttle the app so that they get processed one at a time, everything
is fine.

Regards

Matt

Hi Matt,

Thanks for your message and apologies for the slow reply.

When a POST request hits the /invoices end-point, an in-memory invoice is
created and is automatically assigned the next available invoice reference
in your FreeAgent account.

If you have 10 processes hitting the end-point at the same time, they could
all be given the same reference in memory.
The first process to complete on our server will write the invoice to the
database, claiming that reference for itself and rendering the other 9
invoices invalid when they try to save. This is why you’re seeing the
“reference has already been used” validation error.

For now, if you if want to create your invoices in parallel, you could
compute references in your system and pass them through to our API using
the “reference” attribute. Otherwise, you could send each request in series
(e.g. 1 per second).

Kind regards,
Dave JOn Friday, 28 November 2014 16:58:05 UTC, Matt Roberts wrote:

Hi

Part of our app sends invoices via freeagent, we use the API to generate
an invoice and then send it out.

When I was testing this with 100 bill-runs, with the invoices being
generated in a batch size of 10 (so 10 threads running creating invoices),
we noticed that the (sandbox) free agent API occasionally spits back errors
like this :

[FreeAgentException: StatusCode=422,
Response=RestSharp.RestResponse`1[FreeAgent.InvoiceWrapper],
Content={“errors”:[{“message”:“reference has already been used”}]}]

That response is when we’re trying to add a bank transaction explanation
for the invoice we’ve just added.

If we throttle the app so that they get processed one at a time,
everything is fine.

Regards

Matt