The post has been translated automatically. Original language: Russian
The employee completed the application, but after a few seconds she was back "Working." The reason may be a delayed event from another system.: it was created before it was closed, but it arrived later.
We distinguish between the time of the event and the time of its receipt
For processing, the application ID, the source, the time when the event was created, and its version or sequence number are important. The time of receipt by the server indicates the delay in delivery, but does not determine which change is more relevant.
Checking the validity of the transition
Not every incoming event has the right to change the final state. If the application is closed, the message about the earlier appointment of the contractor should remain in the journal, and not automatically return the entry to work.
Protecting the save from an outdated version
When changing an entry, we compare the expected and current versions. If the state has already changed, the service fixes the conflict and applies consistent logic: rejects the update, recalculates the action, or sends it for analysis.
Testing events in the wrong order
We send "assigned", "completed" and "closed" with a delay, then repeat one of the old messages. We check the final status, the log, and whether there are any unnecessary notifications or repeated tasks.
The correct order in a distributed system is provided by processing rules, not by the hope that all messages will arrive on time.
Сотрудник завершил заявку, но спустя несколько секунд она снова оказалась «В работе». Причина может быть в задержанном событии от другой системы: оно было создано раньше закрытия, а дошло позже.
Различаем время события и время его получения
Для обработки важны идентификатор заявки, источник, время создания события и его версия или порядковый номер. Время получения сервером показывает задержку доставки, но не определяет, какое изменение актуальнее.
Проверяем допустимость перехода
Не каждое входящее событие имеет право менять итоговое состояние. Если заявка закрыта, сообщение о более раннем назначении исполнителя должно остаться в журнале, а не автоматически вернуть запись в работу.
Защищаем сохранение от устаревшей версии
При изменении записи сравниваем ожидаемую и текущую версии. Если состояние уже изменилось, сервис фиксирует конфликт и применяет согласованную логику: отклоняет обновление, повторно рассчитывает действие или направляет его на разбор.
Тестируем события в неправильном порядке
Отправляем «назначена», «выполнена» и «закрыта» с задержкой, затем повторяем одно из старых сообщений. Проверяем конечный статус, журнал и то, не появились ли лишние уведомления или повторные задачи.
Правильный порядок в распределённой системе обеспечивается правилами обработки, а не надеждой, что все сообщения поступят вовремя.
Comments 3
Newest Popular