Migrating My Data From Parse

As you probably already know, Parse announced it’s ending their hosting services on January 28, 2017. The migration plan was divided in two steps: first, we need to host the databases of our apps, and later on we should deploy our own, open source, Parse Server. During the first stage, the clients (iOS, Android, etc.) will keep hitting Parse’s servers, and they will access the newly migrated data; after the second stage is done and your server is up and running, the clients should be updated to point to the new server. The recommended schedule by the Parse team is to migrate the database by April 28, and finish setting up your self-hosted Parse Server by July 28. Yes, you read it right – if you haven’t migrated your database, you have less than a month to do so.

But where should I start from?”, you may ask. As any decision, the pros and cons must to be taken into account, also considering the different conditions: do you have only one or multiple apps on Parse? They store huge amounts of data, or not so much? Do you have experience managing databases, specially MongoDB? How sensitive is your data? What is your budget?

As most of my apps have a small, niche audience, the amounts of data are really small. None of the databases is higher than 10 MB, even with a few thousand users, installation, and other objects. Also, most of them are free, with some humble contributions or donations occasionally. Therefore, I have a small budget to keep them functioning. As I have zero experience managing databases, I can’t build all the MongoDB server by myself (for example, I didn’t even know of some concepts like sharding, replica sets, and more). I started researching all the different options available in the market, to find what would fit my needs.

Ok, so what are my options now?

Suggested by the Parse Team, there are mLab and ObjectRocket, who provide – from what I’ve read – excellent DB-as-a-service. mLab would be a good fit for me, their prices start from U$15 per GB/database/month (the free tier is not intended for production usage). I have around 6 apps in production, and they require different databases, so the monthly cost would be almost U$100 per month, and we aren’t even talking about hosting the Parse Server yet. (Actually, if you are using only Parse Server, and not migrating from hosted Parse, you can use only one database for different apps, by defining a collectionPrefix).

Unfortunately, the prices and sizes that ObjectRocket offer aren’t for indie/side projects, so I needed to cross them as well from my list, together with mLab and Compose.io. While reading the community links and googling more, I’ve found Clever Cloud. I almost chose them to host my DBs: you can host as many mongo dbs you want, and it’s free up to 500 MB; but if you need more than that, it jumps from a free 500 MB, to a 75 €/month for 30 GB, and I needed something in the middle.

Also, as an option for a replacement of all Parse services, there are also NodeChef, ParseGround, Backand and Back4app. But as now I have the possibility to have control over the whole parse stack, I preferred not to depend too much again on another service. It’s a personal decision; check them out because they may be a good fit for you, if you don’t want to worry at all with the backend.

After a few weeks, when I was about to give up, I found Scalegrid.io, that provided exactly what I needed: a place where I can create many Mongo DBs under the same infrastructure (a cluster). Someone to manage the hard part, but with the control that I want. Similarly, there is also MongoDB Cloud Manager, which is an excellent product from MongoDB Inc. itself. I preferred to go with Scalegrid, but the process I describe in the next section is very similar for both solutions.

Setting up my first MongoDB server

After signing up for a 30 day free trial, I checked which one of the services would fit me better: (1) hosting, where I provide my AWS keys or own hardware, and they manage it, or (2) management, where I don’t need to worry about the hardware that will host the dbs. In my case, I preferred to have control also over the underlying instances, so I chose the first option. Price-wise, they are very similar at the end of the day – in the first, you need to pay AWS and Scalegrid.io, while in the second you pay a little more but only for Scalegrid.io. According to my calculations, it would be something very close. So this is what I did, and what you should do to set it up:

  1. Create a new user the AWS account and generate the keys (Acces Key Id and Secret Acces Key). Remember to save this keys, as you won’t get them again from AWS.
  2. Created a new “Cloud Profile” in the Scalegrid console using the AWS keys.
  3. Created a new cluster using this profile. It means that the AWS EC2 instances will be created, by Scalegrid, in your AWS account. Bear in mind that you will need to choose a few options:
    1. Size (micro gives you 10GB of storage);
    2. The version of Mongo (Parse only supports officially 2.6 and 3.0 for now);
    3. To enable replica sets and sharding – if you don’t have high traffic and don’t need redundancy, you probably don’t need;
    4. To encrypt and compress the data – I suggest to set both to yes;
    5. To enable SSL (more on the last paragraph) – it’s recommended, but not required.
  4. Wait for a few minutes (you can see the instance being created in the AWS console), and your cluster will be ready to go.
  5. Now you should be able to get the connection string, needed for migrating your Parse apps, but we are almost done.
  6. For each app, you will need a new database in your cluster. So for each app you have:
    1. Create a new database
    2. add a user (I called mine parse-access) and set a password
  7. Get the connection string, and append the database name at the end. For example, if the database name is SuperApp, your connection string should be: mongodb://user:password@hostaddress:port/SuperApp. (the default port is 27017, and remember to append ?ssl=true at the end).

Finally, an important detail: as one of my apps stores medical data, I wanted SSL to be required. Scalegrid offers two options: self-signed certificates, or use your own, trusted certificates. If you are running only your own Parse Server, the self-signed certificate is enough; if you are migrating from Parse, you will need to get a certificate from a trusted Certificate Authority, or disable SSL at all in your mongo server. I chose the first option:

  1. Purchase a certificate for a subdomain that you own:
    1. You can get a wildcard certificate, for more than one subdomain, or get a certificate for a specific subdomain. (The latter is cheaper and may be enough, so that’s what I did: a $10 certificate via Namecheap/Comodo);
    2. In order to create the certificate, you will need to create a .csr file. Use ssh to connect to the AWS instance and create the .csr;
    3. Provide the .csr file to the Certificate Authority;
    4. Prove that you own the domain (this can be done by e-mail @yourdomain, or using DNS records).
    5. In a few minutes you should receive the certificate files.
  2. In your DNS records, make the certified subdomain point to the Scalegrid server
  3. Finally, install the certificate in the mongo server. (the great Scalegrid support team helped me doing so)
  4. When I thought the SSL journey was over, the migration tool from Parse still wasn’t reaching the servers, showing “No reachable servers”, because the setup wasn’t complete. After researching for a few hours, I discovered that we forgot to add the intermediate certificate.

I’m very happy with the solution I’ve found, but my advice to you is: study the available options, define your priorities and budget, and start the migration process once you chose how to store your data. Be prepared and don’t leave it to the last minute!

Unknown-2.jpeg

If you have any troubles, you can ping me @natanrolnik, or e-mail: me at natanrolnik.me
Thanks to @newFosco, @MarcioK and @ofermorag24  for reviewing this post

Advertisements

6 Comments on “Migrating My Data From Parse

  1. Why not change your app and use the free and reliable and not-going-to-shutdown-ever CloudKit?
    Like you, I have a few apps that use Parse and they don’t make enough money to justify a paid backend. I’ve changed two of them so far and it’s been great.

    • Hey, thanks for commenting.
      Indeed, CloudKit is an excellent option. But for a few people, it’s a bit complicated.
      First, because they may have already lots of data. Secondly, because some people may have Parse in their apps in a non-modular way, meaning that is very coupled to the code and hard to replace.
      How did you do to change them? Besides the code on the client side, how did you handle porting the data?

    • And besides that, of course, there is the fact that Parse has many SDKs out there, Android, web, php, Arduino… While iCloud announced last year only the JS.

  2. My solution of choice is probably a little bit unorthodox: migrate to Microsoft Azure.

    Yup, I had to re-write a lot of my code. But for some smaller projects, this has been less work than I had anticipated. On iOS (as well as Windows, JavaScript and Android), the actual data that travels to/from Azure is structured very similarly to Parse. Additionally, **all** of my custom Parse Cloud Code was transferred with copy-and-paste. And. It. Just. Works! (Yes, the client code to *call* the cloud code is slightly different, but the JavaScript worked perfectly without modification.)

    Maybe not the best choice for everyone, but with a BizSpark subscription (that’s $150/month in free Azure services), I can get a lot done!

    Caveat: When I first tried Azure 2 years ago, just getting up to speed with a simple iOS app was extremely painful. About a year ago, they had clearly made it better, but it was still a work in progress. Now, it’s an easy platform to use; just stick with the older Mobile Services rather than App Services, as it’s better documented and has better and more robust tools.

    • You are welcome, George! Besides mentioning that I personally prefer having my own stack, now that it’s open source, I do think that what you offer is a great solution for many people!
      PS: Vocês são brasileiros também, né? Vamos marcar um FaceTime, quero conhecer vocês melhor e saber mais sobre o Back4App! Sucesso!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: