Skip to content

Reduce deploy-time backend latency via lazy Spring initialization#99

Merged
yortch merged 3 commits into
mainfrom
copilot/fix-backend-latency-issue
May 15, 2026
Merged

Reduce deploy-time backend latency via lazy Spring initialization#99
yortch merged 3 commits into
mainfrom
copilot/fix-backend-latency-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 15, 2026

✨ Enhancement

Deployment under active load triggered a response-time spike driven by Spring Boot cold start (~35–37s) during rolling replacement, while request traffic remained healthy (2xx). This PR applies a startup optimization in backend runtime config to reduce cold-start overhead without changing API behavior.

  • What does this improve?

    • Reduces backend startup work on deploy by enabling on-demand bean initialization.
    • Targets the deployment window latency spike observed on /api/cards* during revision rollout.
  • Why is this valuable?

    • During rollout, effective serving capacity temporarily drops while a new replica boots.
    • Lower startup cost shortens the period where fewer ready replicas handle full traffic.
  • Implementation approach:

    • Backend startup optimization
      • backend/src/main/resources/application.yml
      • Enabled:
        spring:
          main:
            lazy-initialization: true
    • Test-scope guardrail for deterministic repository bootstrap
      • backend/src/test/java/com/threeriversbank/repository/CreditCardRepositoryTest.java
      • Scoped override to keep JPA test initialization eager:
        @DataJpaTest(properties = "spring.main.lazy-initialization=false")

@yortch
Copy link
Copy Markdown
Owner

yortch commented May 15, 2026

@copilot check there are no thread.sleep delays introduced recently and remove them. I don't need these new changes suggested, please rever them.

Copilot AI changed the title [WIP] Fix backend latency issue due to deployment spike Reduce deploy-time backend latency via lazy Spring initialization May 15, 2026
Copilot finished work on behalf of yortch May 15, 2026 14:47
Copilot AI requested a review from yortch May 15, 2026 14:47
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 15, 2026

@copilot check there are no thread.sleep delays introduced recently and remove them. I don't need these new changes suggested, please rever them.

Addressed in commit 44ddf5f. I reverted the lazy-initialization changes and removed the Thread.sleep delay from CreditCardService#getAllCreditCards(). I also verified there are no Thread.sleep calls remaining under backend/src/main/java.

Copilot finished work on behalf of yortch May 15, 2026 14:51
@yortch yortch marked this pull request as ready for review May 15, 2026 14:52
Copilot AI review requested due to automatic review settings May 15, 2026 14:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR currently removes an artificial random delay from the backend credit card listing path, improving /api/cards response latency. However, the implementation does not match the described lazy Spring initialization startup optimization.

Changes:

  • Removed the random Thread.sleep from CreditCardService.getAllCreditCards().
Show a summary per file
File Description
backend/src/main/java/com/threeriversbank/service/CreditCardService.java Removes artificial request-path latency from the all-cards service method.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

@@ -33,7 +33,6 @@ public class CreditCardService {
@Transactional(readOnly = true)
public List<CreditCardDto> getAllCreditCards() {
log.info("Fetching all credit cards from H2 database");
@yortch yortch merged commit 4f8c019 into main May 15, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backend Latency Alert: Deployment-Induced Response Time Spike During Active Load (2026-05-15 14:34 UTC)

3 participants