mirror of
https://github.com/hoppscotch/hoppscotch.git
synced 2026-04-25 16:55:59 +03:00
[GH-ISSUE #5666] [bug]: 100X performance improvement after fixing Database deadlocks in collection/request operations under concurrent load. #2196
Labels
No labels
CodeDay
a11y
browser limited
bug
bug fix
cli
core
critical
design
desktop
discussion
docker
documentation
duplicate
enterprise
feature
feature
fosshack
future
good first issue
hacktoberfest
help wanted
i18n
invalid
major
minor
need information
need testing
not applicable to hoppscotch
not reproducible
pull-request
question
refactor
resolved
sandbox
self-host
spam
stale
testmu
wip
wont fix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/hoppscotch#2196
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @shaezard on GitHub (Dec 5, 2025).
Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/5666
Originally assigned to: @shaezard on GitHub.
Is there an existing issue for this?
Platform
Desktop App
Browser
Chrome
Operating System
macOS
Bug Description
What happened?
When multiple users perform concurrent operations on collections and requests (create, delete, reorder), the backend encounters PostgreSQL deadlock errors causing operations to fail with
INTERNAL_SERVER_ERROR.The deadlocks occur because multiple transactions attempt to update
orderIndexfields simultaneously, creating circular wait conditions.Affected operations:
createRootCollection/createRESTRootUserCollectiondeleteCollection/deleteUserCollectioncreateRequestInCollection/createRESTUserRequestSteps to reproduce
Load Test Results (Before Fix)
Team Collections:
User Collections:
Errors observed
Team Collections:
deadlock detected- 20 occurrences (7.6%)team_coll/reordering_failed- 91 (34.6%)team_coll/creation_failed- 129 (49%)User Collections:
deadlock detected- 21 occurrences (8.08%)user_coll/reordering_failed- 86 (33%)user_request/creation_failed- 88 (33.85%)user_collection/creation_failed- 36 (13.85%)Root Cause
The deadlocks are caused by concurrent transactions acquiring exclusive locks on rows in different orders when updating
orderIndexfields. This creates circular wait conditions that PostgreSQL detects as deadlocks.Proposed Fix
Implement row-level locking using PostgreSQL's
SELECT ... FOR UPDATEto acquire explicit locks on affected rows before performing updates. This ensures transactions acquire locks in a consistent order, preventing deadlocks.New locking methods added to
PrismaService:lockTeamCollectionByTeamAndParent()lockTeamRequestByCollections()lockUserCollectionByParent()lockUserRequestByCollections()Load Test Results (After Fix)
Team Collections:
User Collections:
Files Changed
packages/hoppscotch-backend/src/prisma/prisma.service.tspackages/hoppscotch-backend/src/team-collection/team-collection.service.tspackages/hoppscotch-backend/src/user-collection/user-collection.service.tspackages/hoppscotch-backend/src/team-request/team-request.service.tspackages/hoppscotch-backend/src/user-request/user-request.service.tsAdditional context
Deployment Type
Hoppscotch Cloud
Version
No response
@mirarifhasan commented on GitHub (Jan 16, 2026):
@shaezard Thank you for your work and effort — your PR looks promising.
Would you be interested in contributing to Hoppscotch? If so, feel free to open a PR in our repository. We’d be happy to review it.
@shaezard commented on GitHub (Jan 19, 2026):
Thanks @mirarifhasan . I have opened the PR on the repo.
https://github.com/hoppscotch/hoppscotch/pull/5647/files
This PR has three issues fixed
https://github.com/hoppscotch/hoppscotch/issues/5646 ([bug]: Cross-user/Cross-team orderIndex corruption due to missing teamID/userUid filter in updateMany queries)
https://github.com/hoppscotch/hoppscotch/issues/5654 ([Enhancement] Add cascade delete for collections to improve deletion performance and simplify code)
https://github.com/hoppscotch/hoppscotch/issues/5666 ([bug]: 100X performance improvement after fixing Database deadlocks in collection/request operations under concurrent load.)
@jamesgeorge007 commented on GitHub (Jan 28, 2026):
This is now addressed in the v2026.1.0 release.