-
Hi, I'm seeking advice on designing one or more entities. Let me explain my use case. Imagine a multi-tenant smartphone scenario:
At the moment, I have identified three entities: User, App, and Homescreen. The Widget is not a separate entity but a custom array field within the Homescreen entity. Here's a simplified representation: Playground In this setup, querying a specific User's Homescreen requires just one query. The Widgets on the Homescreen contain the necessary information for rendering (name, order, and size), with the order determined by the array index. However, I face a problem when deleting an App: I must also delete all Widgets referencing that App from all Homescreens. To optimize this access pattern, I've considered treating Widget as its own entity with a secondary index for TenantID and AppID. This would make it straightforward to query and remove all Widgets tied to a particular App upon its deletion. However, by having the Widgets as a separate entity, I lose the array index to order on the Homescreen. I've though about two approaches:
I hope it's not too difficult to understand what I want to achieve :) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Does this sound like I understand the crux of the challenge?:
Is that the extent of your requirements, am I missing anything? |
Beta Was this translation helpful? Give feedback.
-
I threw this together this morning, I only used the playground so don't consider it tested or "complete" but it should get the point across. You want to ensure that your operations remain idempotent so the caller can retry when failures occur: |
Beta Was this translation helpful? Give feedback.
I threw this together this morning, I only used the playground so don't consider it tested or "complete" but it should get the point across. You want to ensure that your operations remain idempotent so the caller can retry when failures occur:
https://electrodb.fun/?#code/PQKgBAsg9gJgpgGzARwK5wE4Es4GcA0YuccYGeqCALgUQBYCG5YA7llXWAGbZwB2MXGBDAAUKKwBbAA5QMVMAG8wAUT5V2AT0IBlTADcsAYziEAwqlxUokgIJUq2AEaoqcACqbpp1eq0BJN0lzcgY3NQ0qTUC4YN9IzQAlOCM5GDAAX24MGzAAIkQUx1gnPIBucVS+KzBUVCx0gF4wAAoASjBGgD4wAHIGJyNeitEqmqoBhFJmvM0oVAwAfQmnKcW+Bkk4csqoaoVLTE6wPjgWeK0W0TAla5uwSVhEAC5b+-v+BNe8w4w8-Du730mFwWD23wAjP9AfdiBhDCZvhNcABrBjSaR5GEZAHvMKOLAuNy4V6KGE3NwbdT+GCk8n3KLeb5WbB8ADm0Pe73IaCw5FpYEc6FxXJx9N+NLpXI…