Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

77%
+5 −0
Q&A Handling high frequency requests with cancellations in an ASP.NET Core application

Issue I have recently discussed with a friend a performance issue he and his colleagues have encountered in an ASP.NET Core 5 application (a checkout app, microservices architecture). The problem...

1 answer  ·  posted 2y ago by Alexei‭  ·  last activity 2y ago by Derek Elkins‭

#3: Nominated for promotion by user avatar Alexei‭ · 2022-02-13T11:39:42Z (about 2 years ago)
#2: Post edited by user avatar Alexei‭ · 2021-11-30T18:32:57Z (over 2 years ago)
minor fix
  • ### Issue
  • I have recently discussed with a friend a performance issue he and his colleagues have encountered in an ASP.NET Core 5 application (a checkout app, microservices architecture).
  • The problematic flow is related to computing the prices of basket items. The computation may take more than it takes the operator to scan the next item. This may lead the Web application (a SPA) to receive an outdated computed basket, due to out-of-order responses.
  • The computation itself is hard to optimize (complex discount computations, the algorithm is O(#items), so it can go up to 1 second for large baskets.
  • Currently, they are exploring optimizing the computation time by replacing the RDMBS with Redis and also identifying and discarding the outdated computed baskets. The solution got pretty complex and has some non-systematic issues.
  • ### My proposal
  • I am wondering if a simpler solution can be used in this case:
  • - [debounce](https://css-tricks.com/the-difference-between-throttling-and-debouncing/) the calls from the UI - the SPA will not immediately reach to API for basket computation. Instead, it will a period of time (e.g. 500ms) from the last item scanned
  • - cancellation - [this article](https://www.davepaquette.com/archive/2015/07/19/cancelling-long-running-queries-in-asp-net-mvc-and-web-api.aspx) shows how a canceled browser request can lead to a SQL query cancellation. This requires that awaitable calls (the project already uses async/await almost everywhere) to use CancellationTokens.
  • This should reduce the strain on the API (no useless computations, since many are discarded anyway) and cancel obsolete computations (if there are some left).
  • As I have no experience with such performance issues, I am wondering about the possible pitfalls of this proposal.
  • The only downsides I have identified so far are:
  • - SPA changes - the app must be changed to introduce debounce and cancellation (none of these are supported now)
  • - API changes - cancellation tokens are not yet used. However, this does not require API breaking changes and could be easily added to the appropriate methods
  • I do not know if the microservices architecture itself introduces risk in this case since there are multiple instances of each service involved in a call graph.
  • ### Issue
  • I have recently discussed with a friend a performance issue he and his colleagues have encountered in an ASP.NET Core 5 application (a checkout app, microservices architecture).
  • The problematic flow is related to computing the prices of basket items. The computation may take more than it takes the operator to scan the next item. This may lead the Web application (a SPA) to receive an outdated computed basket, due to out-of-order responses.
  • The computation itself is hard to optimize (complex discount computations, the algorithm is O(#items), so it can go up to 1 second for large baskets.
  • Currently, they are exploring optimizing the computation time by replacing the RDMBS with Redis and also identifying and discarding the outdated computed baskets. The solution got pretty complex and has some non-systematic issues.
  • ### My proposal
  • I am wondering if a simpler solution can be used in this case:
  • - [debounce](https://css-tricks.com/the-difference-between-throttling-and-debouncing/) the calls from the UI - the SPA will not immediately reach to API for basket computation. Instead, it will a period of time (e.g. 500ms) from the last item scanned
  • - cancellation - [this article](https://www.davepaquette.com/archive/2015/07/19/cancelling-long-running-queries-in-asp-net-mvc-and-web-api.aspx) shows how a canceled browser request can lead to a SQL query cancellation. This requires that awaitable calls (the project already uses async/await almost everywhere) to use CancellationTokens.
  • This should reduce the strain on the API (no useless computations, since many are discarded anyway) and cancel obsolete computations (if there are some left).
  • As I have no experience with such performance issues, I am wondering about the possible pitfalls of this proposal.
  • The only downsides I have identified so far are:
  • - SPA changes - the app must be changed to introduce debounce and cancellation (none of these are supported now)
  • - API changes - cancellation tokens are not yet used. However, this does not require API breaking changes and could be easily added to the appropriate methods
  • I do not know if the microservices architecture itself introduces risk in this case since there are multiple instances for each service.
#1: Initial revision by user avatar Alexei‭ · 2021-11-30T16:55:09Z (over 2 years ago)
Handling high frequency requests with cancellations in an ASP.NET Core application
### Issue

I have recently discussed with a friend a performance issue he and his colleagues have encountered in an ASP.NET Core 5 application (a checkout app, microservices architecture).

The problematic flow is related to computing the prices of basket items. The computation may take more than it takes the operator to scan the next item. This may lead the Web application (a SPA) to receive an outdated computed basket, due to out-of-order responses.

The computation itself is hard to optimize (complex discount computations, the algorithm is O(#items), so it can go up to 1 second for large baskets.

Currently, they are exploring optimizing the computation time by replacing the RDMBS with Redis and also identifying and discarding the outdated computed baskets. The solution got pretty complex and has some non-systematic issues.

### My proposal 

I am wondering if a simpler solution can be used in this case:

- [debounce](https://css-tricks.com/the-difference-between-throttling-and-debouncing/) the calls from the UI - the SPA will not immediately reach to API for basket computation. Instead, it will a period of time (e.g. 500ms) from the last item scanned 
- cancellation - [this article](https://www.davepaquette.com/archive/2015/07/19/cancelling-long-running-queries-in-asp-net-mvc-and-web-api.aspx) shows how a canceled browser request can lead to a SQL query cancellation. This requires that awaitable calls (the project already uses async/await almost everywhere) to use CancellationTokens.

This should reduce the strain on the API (no useless computations, since many are discarded anyway) and cancel obsolete computations (if there are some left).

As I have no experience with such performance issues, I am wondering about the possible pitfalls of this proposal.

The only downsides I have identified so far are:

- SPA changes - the app must be changed to introduce debounce and cancellation (none of these are supported now)
- API changes - cancellation tokens are not yet used. However, this does not require API breaking changes and could be easily added to the appropriate methods

I do not know if the microservices architecture itself introduces risk in this case since there are multiple instances of each service involved in a call graph.