Two people open the same case at the same time and both start typing. Whose changes win? Locking is how Pega answers that question, and it decides whether users see a friendly "someone else is working on this" message or silently overwrite each other's data.
Pessimistic locking
This is the traditional Pega behaviour. When a user opens a case for editing, Pega places a lock on it. Anyone else who opens the case can read it but cannot change it, and sees who holds the lock. The lock is released when the user saves and closes, submits the action, or the lock times out after a period of inactivity (the timeout is a setting on the case class, commonly 30 minutes by default; check your own class).
Optimistic locking
With this option, Pega does not lock the case while people are editing. Instead, when someone saves, Pega checks whether the record has been changed by someone else since it was opened. If it has, the save is refused and the user is told to reload. It suits cases that many people touch briefly and rarely edit at the same time.
Comparison
| Pessimistic | Optimistic | |
|---|---|---|
| Lock while editing | Yes | No |
| Second user | Can view, cannot edit | Can edit, but may lose the race at save time |
| Risk | Users blocked; stale locks | Save conflicts |
| Best for | Long, complex edits | Short, low-contention updates |
A worked example
Two clerks open the same loan application at 10:00.
- Pessimistic: Clerk A gets the lock. Clerk B sees "locked by A" and cannot type. When A saves and closes, B can open it and edit.
- Optimistic: Both can type. A saves first. When B saves, Pega notices the case changed after B opened it and rejects the save with a message. B reloads, sees A's changes, and repeats their edit.
Practical points
- Locks are stored in the database, so they survive a node restart.
- A user closing the browser without saving leaves the lock in place until it times out. Make sure the timeout is sensible.
- Child and parent cases can be locked together, which matters when a screen edits both.
- Test the message users see when a lock exists. A confusing message becomes a support call.
Interview tip
Name both approaches and tell the interviewer which one you would use and why. "Pessimistic when edits are long, optimistic when contention is low" is a good answer. Related: What is Case Management in Pega? and the Case Management label.
No comments:
Post a Comment