Transition to MongoDB and Javascript Framework in 2018

in #mongodb7 years ago (edited)

transitionMongoJS.jpg

There is a transition happening in the world of the web.

With the maturing of Javascript frameworks and NoSQL document-based data storage (amongst other things, but let's not overwhelm ourselves) now would be a great time to make the transition to these technologies in your web projects.

At JKRB Investments we have a culture of constant learning; we have to in the fastest moving industries we are involved with; web, blockchain and AI. We have a natural inclination to test drive new technologies and adopt what makes sense.

Why is this important?

With new technologies come superior deliverable products. Bottlenecks are overcome and running costs decrease. Things become more efficient and easier to manage. Consider that students will be learning breakthrough technology from the off. Everything they are learning now will be superior to the 10-year web veteran.

But experience is priceless in web development and programming. If you started a while back in the web 2.0 era, do not let newcomers leapfrog you. You can catch up, and catch up fast.

I have seen the veteran web developer scenario many times; a 10+ year experienced web developer still offering the same services they have offered for the last 10 years of their career. A web2.0 static website running on an Apache server with MySQL, or a basic LAMP setup perhaps. Maybe their client's websites will be running on a preinstalled CMS such as the now obsolete CPanel. Maybe a clients email is also routed through the same server, resulting in one point of failure; the list goes on.

If you find yourself in this position then it is time for a shake-up. You are not only at a technological disadvantage but an economical one too.

Ask yourself the following questions:

  • Are you receptive to new technologies, or are you biased towards using the ones you learned at school or taught yourself when you first endeavoured into the industry?

  • When was the last time you learnt a new programming language or tool to improve your products?

But wait, a large portion of the web still runs on PHP and MySQL.

The stats can be misleading.

A large portion of the web runs on PHP and MySQL, with Wordpress. This could perhaps suggest that sticking with these solutions for your apps would be OK. However, let's consider that the internet is a constantly evolving landscape with a vibrant open source community, trialling all sorts of ideas and improvements in code from a variety of cultures and ideas.

As a result of this, we have seen changes; here are some related to what we are talking about:

Superior data storage
MongoDB is a superior solution to MySQL; it offers replication and sharding tools so your data is more available and accessible.

NoSQL - schemaless
Unlike a schema based solution, MongoDB stores documents as a JSON formatted record, giving you the flexibility to manipulate individual records to their needs. Although it is wise to stick to a general data structure, storing metadata, expanding the data hierarchy or removing null records is very useful.

Less structuring on the application layer
Documents are fetched as JSON formatted objects (or BSON as Mongo call them, but let's use JSON here). Why is this important? Much less object formatting is needed inside of your application.

Imagine you are fetching product data, product image data, variation data and related products from 4 separate MySQL tables. Once you have those rows of data, you need to format them in a desirable way to pass to your template. Well, as that data can be grouped together into one document record with MongoDB, you only need to execute one fetch request, and that data is already formatted to your desired structure. Go ahead and give that directly to your template (OK, in a real scenario some lightweight formatting will be needed, but to a much less extent than the prior).

Superior management tools
I am referring to MongoDB Compass. A GUI you can download to your machine (Mac, Windows and Linux supported). As well as data management (CRUD), do advanced querying and aggregation directly in the app. Analyse your schema, and see visually how your cluster is performing. (Your cluster is your group of nodes that form your network). Even record live usage of your cluster and run it later on a different cluster setup to compare results.

Security
X.509 based user authentication and node client authentication, MongoDB is fully TLS supported.

Consider the changes that have happened in the environment space in recent history:

  • Facebook created the React framework that runs on NodeJS to power Facebook. (Speedwise, Javascript engines are an order of magnitude faster than PHP7, Ruby and Python).

  • React also has the React Native counterpart that allows native platform programming (Android, iOS) using the React suite and syntax.

  • Google have their own Javascript framework that powers YouTube, named Polymer.

  • Angular is another popular Javascript framework but has recently been adapting itself to more closely mirror React.

The strategy

So you have done your research and want to integrate. You have some great products deployed using legacy software and you want to upgrade them. You are wondering how far you can push your apps - even getting excited about its prospects. Where do you start?

Well, an iterative approach is the only way. Imagine the scenario of wanting to do the following:

  • Move away from your shared hosting and deploy a VPS to run your server
  • Move from Apache to the lightweight fast NginX server
  • Make your app responsive using something like Bootstrap 4, before taking what you actually used and stripping the library.
  • Update vanilla CSS into a SASS solution.
  • Move from a MySQL solution to a MongoDB cluster with replication.
  • Set up a multi VPS solution with XFS formatted data volumes to store your data
  • Move from a PHP based server to a NodeJS and React environment (this is a big one).
    the list goes on (it never stops!)
  • From here I can adopt React Native to create an iOS counterpart.
    ...

This can be overwhelming, and would take months! The only way to tackle this is with an iterative systematic approach. Let's take the above scenario and break it down a bit:

  • I know I can run Mongo with PHP, and data migration is no trivial task. So it makes sense to install the MongoDB PHP driver and migrate my data using an environment I am comfortable with, before changing my PHP infrastructure.

  • But in order to install the MongoDB PHP driver, I need full access to my server. Therefore I will just take my entire solution and copy it to a $5/month VPS server. This way I can familiarise myself with the Linux environment and install the necessary software.

  • I know the Node / React transition will be the most disruptive task, therefore I will complete all previous steps before this.

  • I know that my markup (HTML, CSS and front-end Javascript) will not need amending; I will be able to move them directly to the new server environment, therefore it makes sense to rebuild my SASS styles and minimize my markup before migrating again - I don't want the hassle of migrating my legacy code.

Remember, you want a working bug-free product. Your old pre-upgraded version of your app that is fully working is better for your users than an updated version that constantly breaks!

As a developer,​ you have pride in your final products. We streamline them​ to the best they can be using the current suite of technology that product has adopted. This raises the bar when replacing software with new software - it too has to match the same quality your users expect.

Thoroughly test your solutions before deploying them into production. Develop a solid understanding of how your new tools affect it.

Conclusion

I hope this article was useful to you.

If you are feeling the desire to upgrade your solutions, now is a great time. Having been a web developer for over a decade, I am offering my experience to those who wish to take their products to the next level. I am happy to offer advice and support to other developers, do not hesitate to reach out.