Decoupling Models From Mongo
Hi all -- As part of the effort to separate EdgeX's internal and external model representations, we've made good progress in restructuring the project packages to clearly delineate which code is publicly exportable and which code is usable only my EdgeX internals. Currently, all application logic -- both internal and external -- is pointed to the externally available models located in pkg/models. The long term goal is to change that so that EdgeX has an internal representation of its model which can be changed independently of the contract model.
One of the challenges I've been wrestling with is the coupling we have to Mongo. Our models currently specify BSON serialization metadata (something no client should ever care about) as well as BSON.ObjectID properties and our application logic manages the creation and assignment of BSON.ObjectIDs rather than the underlying database platform. In the future state, if we'd like for the database to be swappable, we have to eliminate explicit knowledge of how to manage database keys and push any metadata about translating a type to a database representation down into the database layer.
Fede has made a good start down a path that will facilitate cleaner separation with his types in the
db/mongo package, but there's more work that needs to be done. I want to summarize some points that I have in mind based on a day and a half of wrestling with how to achieve a clean separation between our business logic and the requirements of the underlying
storage platform. These should not be taken as decisions, but visibility into what I'm currently thinking and an open request for comment.
Thanks for your attention in reading this. I'm not going to proceed any further down this path until I can get some feedback and clarity on the above points. As I said at the beginning, there are real benefits to the work done so far and once the export services have been re-organized to fit in the new package structure, we'll be in much better shape. But there's more work to be done and the primary intent of the original issue I created hasn't been addressed yet.
To ensure we follow through on making sure EdgeX is flexible enough to operate in a customer-defined environment, we have to decouple vendor-specific logic and types from the main application.
Senior Principal Software Engineer
Dell Technologies | IoT DellTech
Round Rock, TX USA