Replies: 3 comments 2 replies
-
It's hard to find an exact way to structure the db, I don't have an answer, but I know certain things about how the database should not be structured. Historically, we had many performance issues caused by structuring the database based on how elements are logically together. For example one, at some point the database was structured like:
This leads to really poor performance in most cases, since it's very natural to subscribe to A better structure is The pattern above has been used recently with communities. Nesting itself is not problematic, it's only an issue when data that has different read/write patterns is coupled together.
would be fine in terms of performance (potentially better, since as @ulisesmac pointed out, this allows us to leverage caching of subscriptions better), as nobody would really subscribe to Note that In wallet, as far as I can see, a lot of stuff is structured in a way that doesn't impact performance, but with one exception that seems to have a similar pattern as above, where we nest I could talk about this forever to be honest, I think it's a very nuanced topic and there's a lot of things to consider, also, my knowledge is limited in terms of actual performance, certain things I haven't really benchmarked etc. But just to come up with something workable, and finding a middle ground between nesting/root keys. Here some assumptions:
The best thing I can come up with, and I am sure is far from perfect is:
So, to give an example from the cases above, if we were to structure a sql database:
You would likely namespace/prefix the two tables. So first example using only root keys: And using namespaces/prefixes: Subscriptions should be (only one example, they are the same basically)
The latter example better leverage layer-2 subscriptions I would think. Overall the SQL analogy seems to hold for the most part, there's some examples where that's a bit more difficult to apply (i.e |
Beta Was this translation helpful? Give feedback.
-
After reading @cammellos's very thoughtful and complete answer I realized one thing... It seems that the main drive for me and others to have grouped state under a root key based on the bounded context was to make it both easier and simpler to understand that part of the app-db state and how it affected the views. It's undeniable, from practical experience in our team, that spreading state into multiple root keys can be detrimental to the comprehension of the app state, at least for many of us. But technically speaking, I think Andrea is right. The app-db should be designed more like a relational database (of course, with all the exceptions considered between this analogy). In the long run, and if we do it right, it can lead to a simpler design, which should offset the more immediate impact in understanding the app state. We can have both things I guess. We can design the app-db with more root keys, normalize more, and so on. We can also devise ways to make multiple root keys be even more "logically connected" (from the dev's perspective). Ideas:
I don't hold any strong opinion. But ever since Andrea shared with me his thoughts and his experience on the mobile team, I'm inclined to favor more root keys (less nesting) and find a way to logically keep them connected without grouping too much at the app-db level. If we move in that direction I could unnest the state for the activity center as a way to share an example. |
Beta Was this translation helpful? Give feedback.
-
Thank you Andrea and Icaro for sharing your thoughts. This knowledge of why was very important before we reach to the conclusion. I like the analogy of database, and it makes sense to me.
And I think not only roots, but we should define clear pattern/instructions for creating new leafs. Otherwise developers will face same question, where should I store it? And as Andrea shared above, we will end up in situation where we are storing everything inside a single key.
Something like this can be part of the guideline, as it explains the logic behind which/why data needs to be separated. |
Beta Was this translation helpful? Give feedback.
-
The current structure defined in
status-im.subs.root
- https://github.com/status-im/status-mobile/blob/develop/src/status_im/subs/root.cljs lacks a clear pattern or strategy. Perhaps there is one 🤷♂️However for developers joining the project it can be unclear of how/when we want to add root keys for given contexts (Wallet, Communities etc)
Providing some guidelines on this would greatly help, and part of that process is defining what we want to get out of our guidelines.
How would you like to see the structure defined? What changes should we make? Or perhaps you like it as it currently is.
Please discuss below.
Some related discussion which helped initiate this
: #18756 (comment)
Beta Was this translation helpful? Give feedback.
All reactions