Scaling Up Node.JS in 7 Steps – From the Diary of a Node.JS DeveloperNode.JS Development Technology
“I write a lot of scripts. But I’m lazy and get bored too quickly to keep writing them over and over. So I thought of writing scripts for everything that has a routine repetition. I find it working for me very well. It reduced errors and gained some productivity. Many of my programmer friends told me how I can use Python or C# or Go for the scripts. But somehow I always choose Node.JS. That's how I landed in a Node.JS Development Company.”
(From a Node.JS developer’s diary, page #167)
It is not a framework. It can be viewed as a run-time environment that performs on the server side. Though it was created 10 years ago, its status as one of the most preferred platform for developers was gained recently. Many organizations such as Netflix, Medium, Walmart, eBay and LinkedIn have used Node.JS in developing their applications and are running at a global scale.
Front end: Gone are the days of composing HTML and contents. Now you can develop a full-fledged website with user authentication and store all its data in the database. As a Node.JS Development Company, we love that we can build an app-like website which updates on click.
While many companies including our clients have used our Node.JS Development Services for their app/web development and have scaled up subsequently, Node has its own set of challenges in scaling up.
Here are some tips and excerpts from our Node.JS Developer’s diary, and they seem insightful.
Three words for you – linting, formatting and type-checking. If you are not following these while writing code, you need to start now. It might be tough to introduce them in the middle of a project because of refactoring and cluttering your git history, but in the end, it helps you write readable, clean code.
You may consider adding ESLint and Prettier to your code base. ESLint is a code linting tool that prevents bad patterns being checked in while Prettier is an automated code formatter which formats all your code in a standard way.
Additionally you can use tools like Flow or TypeScript which will help you catch subtle bugs like calling a function with a number instead of a string, etc. While there will be a learning curve for your Node.JS Development team, these tools help a lot in speeding up development and prevent run-time bugs.
Habit of Writing Tests
It’s a touchy subject for some developers. Within our Node.JS Development team itself, we have people who worship test-driven development and others who love Donald Trump more than testing. What we have seen that mostly works here is a middle ground.
Key modules and flows: You may write thorough unit tests for these areas with focus on “happy paths”, edge cases, and any “bug” scenarios. For other modules, you may write one or two unit tests to cover “happy path” and common edge cases.
Keep UI testing to minimum: UI is something that changes regularly. So it is not prudent to spend time writing tests for code that is going to have regular changes.
Test for bug fixes: Right after when you find and fix a bug, it might be a good idea to write a unit test that would take care of that bug in the future.
A little more tests: Some integration tests might serve good. Go for minimal end-to-end tests to cover key paths in your site. Since these tests are expensive to maintain, you may keep on a small core of tests you think are significant.
Ultimately, you should be able to deploy new code with confidence which is the aim of tests. You may write enough tests which will give you that confidence, at the same time you should refrain from writing a lot of tests too.
Serve Static from a CDN
Serving your static assets from your web application is a good thing since it shortens the feedback loop when you write code. However, serving your static assets via Node.JS is a bad idea. They should rather be compiled separately and served via CDNs like StackPath, KeyCDN, Rackspace, etc. Node.JS makes it unnecessarily slow because CDNs are more dispersed. Moreover, CDN servers are highly optimized for serving small assets. Node.JS server time is much expensive than CDN server time also.
Deploy. Deploy. Deploy.
We have seen at times at least, when we deploy for the first time, it doesn’t work. There could be tiny issues which will make it work locally but not remotely. You would need to deal with such issues regularly during development. Otherwise, a simple fix if caught early, can turn into a critical error in your architecture and we don’t want to do that at any cost.
Tools like Notepad++, Atom, Eclipse, etc., allows you to deploy and validate that things work. Most of those tools have a publicly shareable link so that someone else can check out your progress.
Deploy Two Servers for Horizontal Scaling
Deploying two servers will quickly unearth your issues with horizontal scaling. This way, you would be prepared when it comes to scaling up due to, for example, an expected spike in traffic. As a Node.JS Development Company, we have gone through this a lot and it really helps.
Microservices and Containers
As you develop your application, natural divisions of logic start to appear. For example, one part of the app may process payments while the other draws necessary API data to the front. You may consider making them into separate microservices. Along with added complexities, you have the advantages of scaling them up independently, one part going down without taking the whole app down, lesser coordination with different parts, etc.
This makes the app efficient locally and helps coordinate deploys. You may think of a container like a mini instance of Linux or Windows to run your app in. Docker can help you do that. It is a container technology for Linux that allows a developer to package up an application with all of the parts it needs. You may look at Kubernetes as a tool that plugs all your containers together out in the cloud.
Always Stay on Top of Metrics
You need to know how your app is doing from time to time. Metrics will help you continually improve your app on parameters like slow-running paths, time-to-first-byte, session times, page views, etc. Even your core business decisions might depend on such metrics.
APM (Application Performance Management) tools like AppDynamics and New Relic can be used to monitor, tune and diagnose the performance of applications in real time.
Spericorn as a Node.JS Development Company
Node.JS is getting popular in the enterprise sector where it is chosen by many developers as an ideal platform for scaling up apps.
We constantly work towards making it easier to scale your Node.JS Application with intelligent tools and build your app as your traffic grows.
Reach out to us if this sounds good to you. Or if simply Node.JS excites you in some way.
PS: We have one last Node.JS t-shirt to give away!!