Skip to content

Referential integrity bugs #41

@mafaldacf

Description

@mafaldacf

Hi,

There appears to be code logic that breaks referential integrity constraints and causes inconsistencies during execution. I would like to share this to understand the impact on the application and whether these bugs could be addressed. Thank you in advance.

The issues are related to the data associations established across the order, shopping cart, inventory, and product microservices, where orders, carts, and product inventory contain a product_id that references the product_id of the corresponding product.

Below are the steps to reproduce the bugs and their potential impact on the system.

Steps to reproduce bugs:

The flow of requests is exemplified in a shared figure.
There are two users: a client that manages its shopping cart and orders, and an administrator who manages the products.

  • The client sends a request to the shopping cart service to add a new product to the cart. (fig. calls 1-2)
  • The admin sends a request to the product service to delete that product from the catalogue. (fig. calls 3-4)
  • The client sends a request to the shopping cart service to check out their basket. (fig. calls 5-8)
  • A new order is eventually created through an event that is published by the shopping cart service to a message broker, which is consumed by the order service that proceeds by writing the order to its database and calling the inventory service to decrease the stock. (fig. calls 9-12)

Description of the bugs:

1. When the product is deleted from the product database, the effects are not propagated to the inventory, shopping cart, or order. As a result, the inventory, shopping cart, and order databases are left with references to the product database that are no longer valid, which breaks referential integrity and causes application data to be inconsistent.

2. Even if the effects were to be propagated, additional issues would remain. If the second step (deleting the product) was to be executed concurrently with the third (checking out the basket) and fourth (creating an order) steps, it would not be guaranteed that the shopping cart and/or order service would observe the cascading effects before issuing operations to their databases to perform the checkout and/or register the new order, respectively. For example, if the cascading effect (i) reached the order service before the shopping cart service, and (ii) reached the shopping cart service only after the checkout was performed, then the order would still be created for the deleted product. Consequently, references to the product would become invalid, as new associations would be created in the order database while the referenced product is deleted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions