Best Practices for React, Node.js API and MongoDB
Thomas Jay
Senior Java Spring Boot, Gen AI, API, Python Architect/Developer focused on Performance and Security, building Agile teams and delivering products.
I've been involved in large scale systems for over 20 years and the last 10 years have seen lots of changes, from Monolithic Java/J2EE systems with Oracle back ends to smaller Micro Services based systems with a pure API layer on Node.js Javascript API services with NoSQL integrations with MongoDB and ofcourse front end technologies changing from jQuery to cleaner React JavaScript with Bootstrap as the new presentation layer. Care must be taken to preserve SEO best practices and make the new technology scale even more then before while preserving the ultra new productivity and super low costs of using these new technologies.
I want to highlight a few of the most important things that need to be done when working with these new technologies, with Agile and Scrum processes leading the way, there is less and less formal documentation created and more and more User Stories bringing the new technology into the corporate companies where before only startups would have considered them as a viable solution.
Coding standards for JavaScript are important today, many companies have set standards and its worth searching a bit and find one that fits your company culture. Pair programming and Code review should be the norm with any new project to maintain consistency since in today's market programmer turn over is higher then ever. Clean self documenting code is the norm and must be maintained going forward otherwise written documentation can get our of date quickly and can become miss-leading to new developers working on subsystems.
API's are a core component for any system documentation and using new tools like Swagger/Open API documentation allows your to expose the as built API interface documentation to those who need it while still providing security by limiting access to these resources.
There is a myth that says every developer can work at every level, this is NOT true, there are exceptions but this is not the norm. You would not expect your Database developer to create an amazing UI so why would you expect your UI developer to create amazing database work, it just does not happen that way.
With that in mind, I would like to share some Best Practices for making successful projects that scale and are maintainable.
- Use the latest Libraries as the creator expected, if you use React.js then focus on the Best Practices from Facebook and the React Community.
- Don't get hung up in the Full Stack development myth, don't expect a "MERN" application as a single solution. MongoDB, Express, React and Node. These are all amazing technologies but to throw them together in one application is just another way to create another unmaintainable Monolithic application, you remember the ones your are getting away from.
- Focus on Micro Services, don't let any one component on the front end OR back end take on too much work, let the system scale both horizontally and vertically by adding more instances and loadbalancers rather then by adding complicated code to made things.
- Use formal contracts, what does this mean? Your front end code needs to connect to the back end services with a well defined contract. These contacts are in the form of API's which have a well defined interfaces and are also Versioned. Versioning allows you to support multiple interfaces from outside. Your web application is an outside interface, your mobile devices are an outside interface and your partners are an outside interface. Yes you can update your web page API integrations by just reloading a browser page but you can't force your users on a mobile app to install the latest version, this is just not acceptable. When you have partners using your API's you need to enable their Integrations with versions and security via API gateways, this may be internal or external but in anycase they need to maintain version control since you can not expect your external partners to make changes at the same pace that you do.
- Create your API's as a formal Node.js application connected to MongoDB, use Redis when needed for caching and you can support API's that support millions of users, if its just for general merchandise search or even more detailed transactions like Airline travel, having these in place will allow you to scale simply by adding more load balancers and servers in your micro service layers.
- Don't expect your front end developers to write the same level of code for the back end system, allow people to specialize and become proficient at what they love.
- I see so many React applications today focused on one platform and having the same developers write code for the front end and back end, its a recipe for disaster and rarely wins out.
- Using GitHub and Continues Builds are the norm today, don't miss out of these benefits even if you are not focused on testing, I see so many companies that let developers compile and build apps and then they are deployed by hand, use build and deployment automation tools, there will be the time when a developer is not around and you need to push a build, keep DevOps and Developers in sync and let each group focus on what they know and love.
- Ask experts and peers to take a look and accept input and criticism, no one knows everything and we can all learn now and then!
I'm more then happy to help on your project and I'm looking for the next big thing :)