← 返回 instacart 的题目列表Design and Implement Idempotent Library Notifications for Due Dates and Holds
类型:online_judge
Problem: Implement an Idempotent Library Notification System for Due Dates and Holds
You are working on an existing library management system and need to implement a notification system. The feature requires both frontend and backend changes, idempotency, and full test coverage.
Feature 1: Due Date Notifications
When a patron borrows an item, the system should send notifications:
24 hours before the borrowed item is due.
Again when the item is due.
Requirements:
For the same loan, each notification type should be sent at most once.
Retries, service restarts, or repeated API/job calls must not create duplicate notifications.
If the item has already been returned, no further due-date notifications should be sent.
Feature 2: Hold Notifications
A patron can place a hold on an item.
Rules:
Multiple patrons can place holds on the same item.
Holds are ordered FIFO by creation time.
When copies of an item become available, notify patrons at the front of the queue.
If N copies are available, notify the first N patrons in FIFO order.
Notified holds should be marked as notified/reserved to avoid duplicate notifications.
The process must be idempotent: rerunning the same logic should not duplicate notifications or skip queue order.
Frontend Requirements
Patrons can view their notifications.
Patrons can view their hold statuses, such as waiting, notified, fulfilled, cancelled.
Admin or librarian views should reflect relevant state changes.
Backend Requirements
Design or modify APIs/background jobs, such as:
Create a hold.
Query user notifications.
Process the hold queue when an item is returned.
Scheduled job to scan loans that are due soon or due now.
Testing Requirements
Cover:
24-hour-before-due notification.
Due-now notification.
Returned items should not generate notifications.
Repeated jobs should not duplicate notifications.
Multiple holds are notified in FIFO order.
N available copies notify the first N patrons.
Frontend correctly displays notifications and hold statuses.
Example
Input
Loan due in exactly 24 hours, not returned; notification job runs once
Output
One due_24h notification is created for the patron.