Wednesday, 3 May 2017

How to structure group of MEAN servers

Using MongoDB, Node:

Let's say I'm working on a system for a school district, where each school uses its own server for its campus. At the beginning, I decided to simply make one system that included all of the data for the district, and just filter it appropriately at the application runtime. I chose to do this considering the following:

  • Although the most of the data is distinct, there is a nontrivial amount of overlap. Think of how you'd store a parent with children in multiple schools, or perhaps a teacher/administrator.
  • Each school needs to have its own server. Essential tasks cannot depend on a networked source; read: if a landline goes down, the application must go on.
  • Starting up new schools is a cinch, and if one school goes down, it can just pull the data back from any other.

Of course, there's a rub. Data such as new students aren't added directly to my system (this is a bureaucratic issue). So I have a central server (which also performs various tasks such as data backup, application update pushes, etc) receive the data, and push it out to the school applications.

My issue is how to do this with mongo. When I started, I thought I'd be able to solve this with a master/slaves arrangement (I started a while ago...). Now, looking at the replication format, I see that I'm not going to be able to write to the replicas and sync them to the primary. I need an arrangement where I can write to the replicas and sync throughout the system. Obviously, I must find a way to synchronize the _ids across the schools. I thought of cheating this a bit by creating another field for a system-wide _id (not optimized for mongo), but that seems like it would be an issue for searching by id.

tl;dr: How to maintain MongoDB id's across multiple applications.



via mtro

No comments:

Post a Comment