Skip to content

[Performance] Order processing blocked on database writes — no async/eventual consistency pattern #48

@anshul23102

Description

@anshul23102

Executive Summary

Each order create/update operation synchronously writes to the database, blocking the API response. Under load, response times degrade linearly.

Proposed Solution

@Service
public class OrderService {
  @Async
  @Transactional(propagation = Propagation.REQUIRES_NEW)
  public CompletableFuture<Order> createOrderAsync(CreateOrderRequest request) {
    return CompletableFuture.supplyAsync(() -> {
      Order order = new Order(request);
      Order saved = orderRepository.save(order);
      orderEventPublisher.publishCreated(saved);  // Async event
      return saved;
    });
  }
}

// Controller returns immediately with order ID
@PostMapping("/orders")
public ResponseEntity<OrderResponse> createOrder(@RequestBody CreateOrderRequest req) {
  Order order = new Order(req);
  order.setStatus("PENDING");
  orderRepository.save(order);
  orderService.createOrderAsync(order);  // Fire and forget
  return ResponseEntity.status(201).body(new OrderResponse(order.getId()));
}

Checklist

  • I have searched existing issues and confirmed this is not a duplicate
  • I have read the CONTRIBUTING.md guidelines
  • I have provided clear steps to reproduce the issue
  • I have described expected vs. actual behavior clearly
  • This issue title is clear and specific
  • This repository has been verified as NSOC on https://www.nsoc.in/projects

@pooranjoyb Could you please /assign this issue to me? I would like to implement async order processing under NSOC '26.

/assign

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions