I have a microservice called products, it allows you to do basic CRUD operation on product objects. It consists of a price, a version, quantity, orderId, and title. I have another microservice called orders, it allows you to make orders on products. It has an order item, which has a userId property, a status property, an expireAt property, a product property and a version property.Every time the user updates a product the version increases, every time an user buys x items the quantity is decremented by 1 and the version increases too. However, the buy action is triggered by the order service and this means that there may be a version mismatch and lock both services on that particular product.Every time, someones orders something, an event is transmitted and the product is locked preventing any edit, and an expiration services removes that lock after 15 min. I don't think there's any issue with the order service aside the fact, we update the order on every events issued by the product service.Products listens to order-cancelled, order-created.Orders listens to expiration, product-updated, product-created.The issue is that Products listen to order-created and issues a product-updated event as the quantity changes, but the Product service also allows the user to change their products, and that may affect the version field, should I create another version field for the order-created event?productSchema.set('versionKey', 'version'); productSchema.plugin(updateIfCurrentPlugin); Also, the mongoose-update-if-current library I am using doesn't seem to support 2 keys on one schema. Is there a way to work around this issue?
Submitted June 17, 2020 at 02:45AM by jesusscript
No comments:
Post a Comment