DEV Community

loading...

Monoliths, Microservices & Serverless

kayfortune profile image Fortune Kelechi ・6 min read

Monoliths, Microservices & Serverless.

In the software development landscape today, the three most popular software architectures are Monoliths, Microservices and Serverless. In this article, we are going to outline the different architectures, pros, shortcomings and use cases for each of them with focus on how we can use Fauna to achieve a serverless architecture. At the end, we will see how simple and straightforward it is to develop one with Fauna as the main database component.

Monolithic Architectures

Monolithic applications are applications with a single tier for all of its programs, components such as authorizations, presentations, database and business logic are all available on single program from a single platform.

An example of an application that adopts a monolithic architecture is an e-commerce application that authorizes a customer, takes orders, checks for products in the inventory and authorizes payment. This e-commerce application contains a number of components such as UI and backend logic for inventory, if the application is deployed and building a single application for all platforms, then it’s a monolith!

Pros and Shortcomings of monoliths

Below are some pros of the monolith architecture

  • Easier to develop: It’s much easier to start off a project with a monolithic architecture.

  • Testing: It’s easier to test monolithic applications, for example a UI test could be done using selenium as soon as the application is deployed and launched.

Some shortcomings of monolithic architecture include the following

  • Maintenance: In many cases, monolith applications become too large and complex to understand that it becomes challenging to make changes and add new features fast.
  • The application becomes cumbersome and large as more features are added.
  • The entire application must be deployed after a new feature or update is made.
  • Reliability and slow to adapt to new technologies: For monolithic applications, this is because a changes in a language or framework can affect or bring down the whole application.

Microservices Architecture

A microservice architecture is implemented while building a single application as a series of small applications, with each running their own processes and communicating with each other. Simply put, microservice is an technique where a large application is built as a set of independent components.

With microservices, each service can have a separate database and communication between the components is done with APIs. Use cases include refactoring legacy apps, applications that work with big data example ML/AI, Real-time data processing applications.

Benefits of Microservices

  • Microservices helps with continuous delivery and deployment of large applications.
  • Improves testing of applications due to their small sizes.
  • Improves deployment - services can be deployed as independent applications.
  • Improves collaboration between teams, in the sense that each team is taxed with building a single service or more. each team can develop, deploy and scale services independent of the other teams.
  • Improved error handling: With microservices if a service is down, other services continue to handle requests from users unlike monoliths where a single fault can cause the entire application to crash.

Cons of Microservices

  • Creating a distributed team can be very tasking for developers.
  • Testing is sometimes difficult due to the large number of components.
  • Deploying separate components that make up a single system can be quite complex.
  • Implementing communication between multiple services can be very tasking on the team.
  • Increased memory consumption due to multiple services.

Serverless Architecture

Often known as the next big thing in cloud computing, serverless is a way firms and developers outsource server management to cloud providers who manages the allocation and provision of servers. It’s an architectural style where application development is based on third-party services who manage server logic for businesses.

Use cases that can benefit from serverless architectures include IoT, Virtual assistants and chat bots, image rich applications and CI apps.

Pros of Serverless Architecture

Below are some pros of serverless architecture

  • It’s cheaper than the traditional cloud: With serverless, you pay a fraction of the average of the price based on your usage.
  • Scalability: With serverless, you are ready for any measure of growth and scaling is easier compared to other architectures.
  • Lower human costs: With serverless, you reduce the cost of hiring entire teams to manage your servers and architecture.
  • Focus on User Experience:** With server management outsourced, teams can focus on improving the user experience.

Cons of Serverless Architecture

  • Vendor lock-in: With serverless, you’d have to play by rules and regulations specific to the platform you’re using for your app.
  • Learning curve: For most developers, the learning curve for serverless can be quite steep.
  • serverless is argued to be unsuitable for long term tasks, this is because for long duration tasks require additional functions.
  • Cost can not be predicted this is because the number of executions isn’t defined.

Why you should use serverless for your next application

In this section, we’d be talking about the benefits of going serverless for your next application, they include

For most developers, building APIs to manage the different sections of an applications can be and is tasking, building platforms to handle payments, transactional email, user analytics, CI/CD etc.

With serverless, there are many other services that, handle payments (Stripe), SMS processing and delivery (Twilio), Cloud Database Fauna. With serverless, instead of spending a lot of time on building and maintaining infrastructure for an application, developers can focus on optimizing an application and improving the user experience.

With serverless, teams can build scalable, coupled infrastructure faster and more efficiently for applications. For database accesses, serverless have always been preferable due to how fast it takes to spin up a new application.

Building A Serverless Notes App with Fauna

In this section, we are going to focus on building a serverless application with Fauna and React.js, with Fauna we don’t have to worry about a lot of stuff such as setting up our database and scaffolding and with user authentications, because Fauna provides us with server keys that make this easy for us.

Let’s get started!

Scaffolding our React application

To get started, let’s create a react application using the command below:

create-react-app fauna-notes-app
Enter fullscreen mode Exit fullscreen mode

The above command creates a react application with the project name we inputed. Next, we will create the three folders below in the src directory of our project.

  • components - This folder will handle all our components for our application.
  • db-config - This folder will handle all our database related logic.
  • api - Here, we will write code for our FaunaDB queries and logic.

Setting up Fauna

To setup our fauna database for our application, first head to Fauna and create an account if you haven’t. Next create a new database notes_app.

Alt Text

We’d need a secret key (Fauna secret) for our application as it will be the connection between our react application and our Fauna database, to get a key we’d need to create a role. We do that by navigating to the the security section of the dashboard and click on keys then create a new key, like the image below

Alt Text

Our access key should appear as soon as we save the new role for our key, when you see the access key, save it for later use, next Let’s create a collection for our application. A collection is similar to a table in SQL powered databases. To create our document, we’d follow the image below

Alt Text

After creating a collection, next is to create an index for our collection, with indexes we can retrieve our data more efficiently and effortlessly. You can learn more about indexes here. In the next section, we will be connecting our React application to our fauna database.

Connecting React App to a Fauna database

Our frontend application is a React.js note taking application built using React, Bulma.css for styling and toastify for notifications. For convenience sake, I’ve prepared our frontend application and added an env file which you can copy to create your own and connect your Fauna instance to using your access keys. First, clone my repo using the format below

git clone https://github.com/iamfortune/fauna-notes-app
cd fauna-notes-app
yarn install 
cp .env.example .env
Enter fullscreen mode Exit fullscreen mode

If you’ve done this add the text below to your env file with the keys you saved before.

REACT_FAUNADB_KEY=your-keys-go-here
Enter fullscreen mode Exit fullscreen mode

If you’ve done this, run the command below to start your application.

yarn start
Enter fullscreen mode Exit fullscreen mode

If done correctly your application should look like this

Alt Text

Conclusion

In this article, you’ve learned how to set up a Fauna database, create roles and indexes in Fauna. You can take this further and add more functionalities to the application, or build new things with Fauna.
We also learnt that microservice is an technique where a large application is built as a set of independent componentswhile monoliths are applications built as single tier systems.
It’s important to note that Fauna was built with scalability in mind and so will scale automatically as your application’s database needs grows. You can learn more about Fauna from the references below.

RESOURCES AND REFERENCES

Getting Started with Fauna

Discussion (0)

Forem Open with the Forem app