0

Our system needs to process PDF invoice files from generic external third parties.

Using HTTP is the most obvious, but this isn't the greatest of ideas in case we need to deal with bulk uploads.
Even when we push all HTTP requests on a queue behind the http controller, when thousands of PDF's are sent to the server as a batch process by different clients, I feel this will be too much. (Edit: we may at least initially solve this with rate limiting as it concerns as startup idea).

It makes more sense to expose a queueing system (like amqp, since we will use RabbitMq internally), but our clients should be generic, and we can't impose the necessity of implementing amqp to our clients. It isn't as omnipresent as HTTP clients.

Is there a third option you could advise that I'm currently not seeing?

4
  • 1
    Is there a reason to not use ftp? Commented Jul 1, 2022 at 2:40
  • 1
    Do you have any evidence to support your feeling that HTTP will be insufficient?
    – JonasH
    Commented Jul 1, 2022 at 6:46
  • @candied_orange Yes, the external clients are generic. The system is for the major part based on blockchain, and it's not the purpose that we will set up a special ftp connection for each supplier.
    – Trace
    Commented Jul 1, 2022 at 17:55
  • @JonasH Not evidence, but sending pdf invoices is something we do internally in our company through filesharing. For a bulk processes, let's say a few times per year sending a million http requests, seems strange. But maybe I'm wrong.
    – Trace
    Commented Jul 1, 2022 at 17:56

1 Answer 1

2

It makes a lot of sense to use a HTTP API for the public API, simply because tooling and security of such APIs are very well-understood.

But of course it also makes sense to use a message queue so that the tasks can be processed asynchronously.

This is not a contradiction. You can use the message queue purely internally. You mention this approach but discard it because “when thousands of PDF's are sent to the server as a batch process by different clients, I feel this will be too much”. But why would that be too much? A couple of thousand messages is not a lot.

If you are concerned about the storage size of the message queue, then you might consider storing parts of the data out-of-band. For example, you might store the uploaded PDFs in an S3-like object store or other database, and then only put a link to this PDF into the message that is sent via the message queue.

If you are concerned that one user's bulk uploads could block other users' tasks, then you can take appropriate steps to ensure fair scheduling of the work. Rate limits alone might not be sufficient. If the rate limit is so high that it is possible to accumulate a backlog of work, then all tasks submitted at the same time will have equivalent latency. In contrast, it might be desirable to increase latency for bulk uploads, but still allow speedy responses for other users. You can achieve this using a priority queue, where the priority for one user's messages decreases as the number of their pending tasks increases. I would expect a function of the type prio = maxprio - log(n_pending_items, b) to provide some useful properties, but I'm not that deep into Quality-of-Service (QoS) algorithms.

An alternative way to deal with large queues of pending tasks is to dynamically scale your compute resources as necessary, which is feasible in a cloud setting. In case the tasks are processed by a serverless Function-as-a-Service offering, such scaling might also happen automatically.

3
  • Thanks for your answer. It is not very obvious from my post, but I take a lot of consideration into security. Sharing pdf's over S3 is of course an option, but our system will revolve around whitelisting invoices through a Hedera smart contract on Hashgraph (blockchain-like tech). In the backend we store our pdf's in ProvenDb, which is based on proofs generated based on MerkleTrees). This is why we prefer not to add too many external dependencies if it is not necessary. Security is the main business proposition with as few weaknesses in the chain as possible.
    – Trace
    Commented Jul 1, 2022 at 17:59
  • Also thanks for your tip about the priority queues. This is an interesting approach that I will consider.
    – Trace
    Commented Jul 1, 2022 at 18:01
  • To respond to your comment on 'a couple of thousand'; this was poorly phrased from my part. It is not thousands; in bulk uploads we may speak of millions for a single supplier. This however is probably not something I should be worried about initially, so I agree that it shouldn't matter at the start.
    – Trace
    Commented Jul 1, 2022 at 18:31

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.