xxxxxxxxxx
var express = require('express')
var app = express();
var port = process.env.PORT || 3000;
var routes = require('./api/routes');
routes(app);
app.listen(port,function(){
console.log('Server started on port: ' + port);
});
xxxxxxxxxx
-> Microservices-based architecture lets you split your application
into small units.
-> Each part can independently deploy and scale;
it does not matter if different programming languages and teams write it.
-> You can also test the small units individually.
xxxxxxxxxx
// Microservices are small components that together work to make your app work.
// Let's see an example!
// You wanna make a forum app for example
// You will have
// - Users
// - Posts
// - Notifications
// Instead of making all of that into one big services, we split it up
// One service manages the user, for example (pseudocode javascript)
const db = require('db');
if (!db.find(username)) {
send(handle(Error.NOTFOUND))
}
const dbAccount = db.find(username);
const passwordHash = dbAccount.password;
const enteredPasswordHash = hashFunction(enteredPassword);
if (passwordHash === enteredPasswordHash) {
send(generateUserToken(dbAccount))
}
else {
send(handle(Error.WRONGPWD))
}
// Another microservice for posts
if (requestType === RqType.POST) {
db.add('post', {
id: accountId,
username: accountUsername,
title: title,
replies: [],
upvotes: 0,
postId: uuidv4(),
});
notificationsMicroservice.communicate('post_sent');
} else if (requestType === RqType.DELETE) {
db.remove('post', requestPostId);
}
// And the notifications microservice
on.event('post_sent', (context) => {
const notif = {
title: `New post by ${context.poster}`,
message: `${context.poster} just posted a new post! Come check it out`,
picture: context.posterPfp,
};
context.send(notif);
});
// This makes your application clean and concise with everything being split in
// its own small service