Skip to content

Foreign Constraint Error/Race Condition on TeamUser Projection #27

@bponghneng

Description

@bponghneng

Description

The user registration workflow triggers the UserRegistered process manager, which creates a user, creates a team and then adds the user to the team. All three have read model projections. The TeamUser projection may attempt to project a team user association before the Team and User projections have finished, which causes a foreign constraint error.

Steps to Reproduce

Run mix test for the following files which test the user registration workflow:

  • test/reply_express_web/controllers/api/v1/users/registration_controller_test.exs
  • test/reply_express/accounts/users_context_test.exs
  • test/reply_express/accounts/users_context_test.exs

Recommended Solution

See usage of the error/2 callback on the Elixir Commanded.Projections.Ecto package and Commanded.Event.Handler package. Introduce a retry after delay:

  • https://hexdocs.pm/commanded_ecto_projections/usage.html#error-handling
  • https://hexdocs.pm/commanded/Commanded.Event.Handler.html#c:error/3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    In progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions