I have a subsystem that contains sensor data and posts it to the Internet via TCP or UDP requests to a server with authorization by token. All the posted data is also saved to a local capped MongoDB database.
I want this system to be tolerant to network failures and outrages and to be able to synchronize data when the network is back.
What is the correct way to implement this without re-inventing the wheel?
I see several options:
- MongoDB replication.
- PROs:
- Replication tools exist
- CONs:
- How to do that in real-time? Having two systems: to post one way when the system is online and the other way when the system is offline seems to be a bad idea.
- No idea how to manage access tokens (I don't want to give direct access to the server database)
- Server side scheme should match the local one (but can be PRO since then manual import is trivial)
- PROs:
- Maintaining 'last ACKed' records and and re-transmitting once a while.
- PROs:
- Allows for different data scheme locally and on server side
- Works
- CONs:
- Logic is complex (detect failures, monitor for network connectivity, etc)
- Exactly opposite from 'reinventing the wheel'
- Manual data backfeed is hardly possible (e.g. when the system is completely disconnected for a long time and data is restored from back-ups).
- PROs:
I want a simple and reliable solution (the project is in Python, but I'm also fine with JavaScript/CoffeeScript in a separate process). I prefer a Python module that is tailored for this task (I failed to find one) or a piece of advice of how to organize the system UNIX way.
I believe this is a solved problem and has a known best practices which I ceased to find.
Thank you!