1

I have built a laravel web application for a client of mine which runs on a dedicated server.

The system is a booking system, and the client needs access to this at any time during the work day. So he came to me with "What happends when I loose my internet connection?".

The solution I am going to implement for my client is that I will set up a Raspberry Pi that will run the same web application locally at their shop. So if the loose their internet connection, they can access the web application served from the Raspberry instead.

However, what I now need, is that the Raspberry at all times when it has internet connection, syncs up with the latest information about booked appointments from the live server. And when the internet connection goes down and they use the local web application to book new appointments, then I need the raspberry to tell the live application about those new hours that are booked when the internet connection comes back on.

I have been looking at replication-sets, but it looks like I need a third server to be a judge here for the system to work in such a way that the slave gets writing capabilities to its mongdb server.

Can anyone help me out with any ideas here?

Thanks.

3

You'll need to find a different approach as there are a few major assumptions that won't work.

The solution I am going to implement for my client is that I will set up a Raspberry Pi that will run the same web application locally at their shop

Raspberry Pi 1/2 (with 32-bit ARM CPU) is not an officially supported platform for MongoDB, nor is it likely to be. The MMAP storage engine (which is the only 32-bit storage engine available for MongoDB) also has a limitation of ~2GB of data on 32-bit deployments as per the underlying MMAP API. There are some community builds which might be passable for development use, but I wouldn't recommend for client/production work.

There is progress toward experimental 64-bit ARM support in the MongoDB 3.3 development branch, so support for Raspberry Pi 3 or newer is an eventual possibility. If you want to run a full-featured web application with minimal compatibility hassle, a small form factor 64-bit x86 computer is a better bet for current deployments.

So basically, I need the Pi to be a slave, which becomes master when no inet, and writes to the master when the inet is back up

This isn't a supported replication model as at MongoDB 3.2; a replica set can only have a single primary which accepts writes. An offline/disconnected secondary would be read-only.

"What happens when I lose my internet connection?".

Some other approaches to consider:

  • Set up a backup internet connection. This will minimise complexity since you don't have to worry about conflicting versions of data or applications.

  • Look into a different local storage solution for offline writes which is also more suited for embedded / low power devices (for example, SQLite). You'll have to work out how to resolve data editing conflicts between local & web data, though.

1
  • Hm, the alternate offline solution seems reasonable. Maybe as sort of a lightweight message queue of some oplog-ish messages? With a "last_update" field it would become relatively easy to decide which is the most current edit. – Markus W Mahlberg May 17 '16 at 23:12
0

You can replicate data from one server to others using Replication feature in MongoDB.

The replica set ensures high availability and redundancy of you mongodb data in case if node failure. In your case, you can create a replica set of 3 nodes (PRIMARY, SECONDARY, ARBITER). When one of the server goes down, Secondary would be promoted as PRIMARY which ensures high availability of MongoDB data.

It is always recommended to have at least 3 members in replica set.

You can find detailed document here

2
  • The reason I am doubting this solution is just because of the arbiter. In a normal web app environment, it would be a good solution. But since the mentioned raspberry Pi is only going to be located behind the shops router and used for when their router looses internet connection, it cannot connect to an outside Arbiter. Also, using the raspberry pi as an arbiter is not a optimal solution, due to it being a raspberry pi at a not so great internet connection. So basically, I need the Pi to be a slave, which becomes master when no inet, and writes to the master when the inet is back up – Ole Haugset May 13 '16 at 19:01
  • And yeah. Since this is a web application, any employee can have updated the live environment from their homes while the internet was out, so both of the databases can have had changes done to them while the shop have lost internet connection. Thus, its not as much "writing to the master" as merging the changes between those two – Ole Haugset May 13 '16 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.