bee icon indicating copy to clipboard operation
bee copied to clipboard

429 Errors When Buying Batches in Parallel

Open nugaon opened this issue 1 year ago • 3 comments

Context

  • Bee version: 2.2

Summary

When attempting to buy postage batches, the operation takes a long time and cannot be performed in parallel with other postage post API calls. This results in a 429 status code, indicating that simultaneous on-chain operations are not supported.

Expected behavior

Buying postage batches should be efficient, and it should be possible to perform this operation in parallel with other API calls without receiving 429 status codes.

Actual behavior

When trying to buy postage batches in parallel with other API calls, the system returns a 429 status code. The logs indicate that simultaneous on-chain operations are not supported:

"postage access: simultaneous on-chain operations not supported"

This suggests that the current locking mechanism may be overly restrictive, potentially affecting the performance and scalability of the system.

Steps to reproduce

  1. Start multiple postage batch purchases in parallel with other postage post API calls.
  2. Observe that some operations fail with a 429 status code.
  3. Check the logs for messages indicating that simultaneous on-chain operations are not supported.

Possible solution

Review and possibly redesign the locking mechanism used during the postage batch purchase process. While the nonce handling needs to remain synchronous to prevent duplicate transactions, other parts of the process could potentially be handled in a more concurrent manner. This could improve the responsiveness and scalability of the system.

nugaon avatar Oct 11 '24 10:10 nugaon

To clarify, are you suggesting

  1. Purchase of multiple postage batches in parallel
  2. Purchase of a single batch and call another API (like topup or dilute) in parallel
  3. 1 and 2

acha-bill avatar Oct 14 '24 17:10 acha-bill

the first option

nugaon avatar Oct 15 '24 08:10 nugaon

I don't think there's much we can do to enable parallel usage of the buy stamp endpoint. It's mostly just

expire limited batches
balance check
send approve tx
send buy tx
save stamp

BTW, it returns an "unuseable" stamp only in a few seconds. The stamp then needs a few minutes to become useable - That's not related to this endpoint.

While this endpoint shouldn't be called in parallel, factoring out the wait period might help to parallelize your flow.

acha-bill avatar Oct 15 '24 09:10 acha-bill