Understanding Service-Oriented Layer Architecture (SOLA): A Comprehensive Guide

Ali Ahmad Jan
5 min readNov 13, 2023

--

In the realm of software development, architects and developers are continually exploring various architectural patterns to design scalable, maintainable, and modular systems. One such architecture that has gained prominence is the Service-Oriented Layer Architecture (SOLA). This blog will delve into what SOLA is, its benefits compared to other architectures, and scenarios in which it’s most beneficial.

What is Service-Oriented Layer Architecture (SOLA)?

Service-Oriented Layer Architecture, also known as Service-Oriented Architecture (SOA), is an architectural style that structures an application as a collection of loosely coupled, independently deployable services. These services can be thought of as self-contained units that perform specific business functions and communicate with each other through well-defined interfaces.

Key Components of SOLA:

  1. Services: The fundamental building blocks in SOLA are services. These are independent, reusable components that encapsulate specific business logic.
  2. Interfaces: Services communicate with each other through well-defined interfaces, often using standardized protocols like HTTP, SOAP, or REST.
  3. Loose Coupling: SOLA emphasizes loose coupling between services. Each service operates independently, and changes in one service do not directly impact others.
  4. Scalability: Services can be scaled independently based on demand. This allows for better resource utilization and responsiveness.
  5. Discoverability: Services in SOLA can be discovered and accessed dynamically through service discovery mechanisms.

Folder Structure of SOLA with an example:

This is the basic folder structure to follow, you can add more folders according to your requirements

So let me explain you guys with a basic example of “Creating A New User” using this architecture

Note: I am using Node Js with PostgreSQL as database and sequelize as an ORM

Step 1: Go in models folder and a make a new file users.model.js according to your needs

const jwt = require('jsonwebtoken');

module.exports = (sequelize, Sequelize) => {
const Users = sequelize.define('users', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true,
},
name: {
type: Sequelize.STRING,
allowNull: false,
},
phoneNo :{
type: Sequelize.STRING,
allowNull: false,
},
gender: {
type: Sequelize.STRING,
allowNull: false
},
email: {
type: Sequelize.STRING,
allowNull: false,
},
password: {
type: Sequelize.STRING,
allowNull: false,
},
createdAt: Sequelize.DATE,
updatedAt: Sequelize.DATE,
});

return Users;
};

Step 2: Connect your model with database, so that table gets created automatically


const database = require("../database/db.config")
const SequelizeMain = require("sequelize");
const sequelize = new SequelizeMain(database.DB, database.USER, database.PASSWORD, {
host: database.HOST,
dialect: database.dialect,
port: database.port,
logging: false
});
sequelize
.authenticate()
.then(() => {
console.log("Connection to the database has been established successfully.");
})
.catch((err) => {
console.error("Unable to connect to the database:", err);
});
const db = {};

db.Sequelize = SequelizeMain;
db.sequelize = sequelize;

db.users = require("./users.model.js")(sequelize, SequelizeMain);

sequelize.sync();

module.exports = db;

Step 3: Once your Connection to database has been established successfully, you move towards writing business logic and then creating user

So in the services folder, make a new file named users.service.js and write the business logic

const db = require("../models");
const Users = db.users;
const bcrypt = require('bcrypt');
const logger = require('../common/winston');
const userService = {
// Create A New User
createUser: async (req) => {
// Validate the user data
if (!req.name) {
throw new Error('Please provide name');
}

// Hash the user's password
const salt = await bcrypt.genSalt(10);
const hashedPassword = await bcrypt.hash(req.password, salt);
userData.password = hashedPassword;
// Create the user
const user = await Users.create(req);
return user;
},
}
module.exports = userService;

Step 4: After writing business logic in services foler, move towards controller folder and make a new file there named users.controller.js to call that service function you wrote

const userService = require("../services/users.service")
const logger = require('../common/winston');
const userController = {
// Creates A New User
createUser: async (req, res) => {
try {
const user = await userService.createUser(req.body);
logger.info('User Created Successfully!');
return res.status(200).send({
success: true,
message: "User Created Successfully!",
data: user,
})
} catch (error) {
logger.error('Error Creating User!')
return res.status(400).send({
success: false,
message: "Error Creating User!",

})
}
},
}
module.exports = userController

Step 5: Now you have to call this function to test, now go in routes folder and create a new route file there named users.route.js

module.exports = app => {
const Users = require("../controllers/users.controller");
var router = require("express").Router();
// Create a new User
router.post("/create", Users.createUser);
app.use("/api/users", router);
};

Step 6: In your server.js call this route

const express = require("express");
require('dotenv').config();

const app = express();
app.use(express.json());

// parse requests of content-type - application/x-www-form-urlencoded
app.use(express.urlencoded({ extended: true }));
require("./routes/users.route")(app);

// set port, listen for requests
const PORT = process.env.LOCAL_PORT;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}.`);
});

Step 7: You can test using Postman or frontend

Benefits of Service-Oriented Layer Architecture:

1. Modularity and Reusability:

  • SOLA promotes the development of modular and reusable services. Each service encapsulates specific functionality, making it easier to understand, maintain, and extend.

2. Loose Coupling:

  • Loose coupling between services allows for independent development and deployment. Changes to one service do not necessitate changes to others, fostering agility and flexibility.

3. Scalability:

  • Scalability is achieved at the service level. Critical services experiencing higher demand can be scaled independently without affecting the entire application.

4. Interoperability:

  • SOLA enables interoperability between services developed using different technologies. As long as services adhere to the specified interfaces, they can seamlessly communicate.

5. Fault Isolation:

  • In case of a failure in one service, others can continue to function. This fault isolation prevents the entire application from being affected by a single point of failure.

6. Technology Neutrality:

  • Services in SOLA can be implemented using different technologies and programming languages. This flexibility allows teams to choose the best technology for a specific service.

7. Improved Maintainability:

  • Due to modularity, services can be updated or replaced without affecting the entire system. This ease of maintenance contributes to a more sustainable and long-lived architecture.

When and Why to Use Service-Oriented Layer Architecture:

1. Large and Complex Systems:

  • SOLA is particularly beneficial for large and complex systems where breaking down functionality into smaller, manageable services promotes maintainability and scalability.

2. Diverse Technology Stack:

  • When an organization uses a diverse technology stack, SOLA allows different services to be implemented using the most suitable technologies, promoting flexibility and innovation.

3. Dynamic Scaling Requirements:

  • Applications with varying and dynamic scaling requirements benefit from SOLA. Services can be scaled independently based on demand, optimizing resource utilization.

4. Interoperability Needs:

  • In scenarios where interoperability with third-party systems or integration with legacy systems is crucial, SOLA provides a standardized approach to communication between services.

5. Agile Development:

  • For teams practicing agile development methodologies, SOLA aligns well with iterative and incremental development. It facilitates the quick and independent deployment of services.

6. Evolving Business Requirements:

  • As businesses evolve, so do their requirements. SOLA accommodates changing business needs by allowing the addition, removal, or modification of services without disrupting the entire application.

7. Service Reusability:

  • Organizations aiming to maximize the reuse of code and functionality across different parts of the application or across multiple applications can leverage SOLA.

Conclusion:

Service-Oriented Layer Architecture stands as a powerful paradigm for designing and building robust, scalable, and maintainable software systems. Its emphasis on modularity, loose coupling, and scalability aligns with the needs of modern applications. When implemented thoughtfully, SOLA provides a framework that adapts to the evolving landscape of business requirements, making it a valuable choice for architects and developers looking to build resilient and future-proof systems.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response