And a 5 min introduction to Archiejs - a library for writing modular code in Nodejs.
http://bit.ly/archiejs-demo
http://bit.ly/archiejs-demo
http://bit.ly/archiejs-demo
http://bit.ly/archiejs-demo
halfchess.com
http://bit.ly/archiejs-demo
Startups
pre product-market fit,
experimental stuff
Mid-sized
service companies or products with some traction
Unicorns
Big traction,
Consumer internet companies, etc
Startups
~ 95%
Mid-sized
~ 5%
Unicorns
~ 0.01%
SOA vs Mircroservice is about Agility in large teams; and not about scalability.
over microservices
Monolith: 3 vs Microservices: 0
Monolith: 0 vs Microservices: 2
Microservices: 2 vs Modular Monolith: 5
Messy Monolith
Micro-service
Modular Monolith
Micro-service
Sander Mak's 'Modules or microservices?' is a great talk where I first saw the ISS example for modular architectures.
Book ticket
Cache Lib
cache.js
Reserve ticket
Ticket Db
db-wrap.js
Implementation
booking.js
Setup
{ imports, config }
uses cache module
ticket DB module
Module Interface
Tests
/test/
Metadata package.json, index.js
Domain
Aggregator
Booking
Customer (ie. user)
Authentication
Interface
Web-express
SMS-twilio
Messenger-chat
Ticket Booking App
Modular Directory Structure
Payments
Database
User
Venue
Ticket
Domain
Aggregator
Booking
Customer (ie. user)
Authentication
Interface
Web-express
SMS-twilio
Messenger-chat
Ticket Booking App
Modular Directory Structure
Payments
Database
User
Venue
Ticket
>> Readability
Domain
Aggregator
Booking
Customer (ie. user)
Authentication
Interface
Web-express
SMS-twilio
Messenger-chat
Ticket Booking App
Modular Directory Structure
Payments
Database
User
Venue
Ticket
>> Readability
>> Maintainability
Domain
Aggregator
Booking
Customer (ie. user)
Authentication
Interface
Web-express
SMS-twilio
Messenger-chat
Ticket Booking App
Modular Directory Structure
Payments
Database
User
Venue
Ticket
>> Readability
>> Maintainability
>> Reusability
Domain
Aggregator
Booking
Customer (ie. user)
Authentication
Interface
Ticket Booking App
Modular Directory Structure
India-Aggregator
US-Aggregator
Payments
Database
India-Payments
US-Payments
EU-Payments
>> Agility
or, Teamwork
Disadvantages:-
Book ticket
Cache Lib
(cache.js)
Reserve ticket
Ticket Db
(db-wrap.js)
Implementation logic
Booking Directory
Another
Directory / Module
like npm modules
additional abstraction and dependency injection
Rules enforced:-
/domains/booking/index.js
/** fetch config **/
import { redisConfig } from './../../config/env';
/** consumes services from modules **/
import { ticketDb } from './../../models';
import { cache } from './../domain/cache';
/** initialize implementation files **/
import initImpl from './impl';
/** provides services **/
const { availableSeats,
reserveSeat,
confirmSeat,
cancelSeat,
} = initImpl(redisConfig, cache, ticketDb);
export const {
availableSeats,
reserveSeats,
confirmSeat,
cancelSeat
};
Disadvantages:-
/domains/booking/index.js
/** fetch config **/
import { redisConfig } from './../../config/env';
/** consumes services from modules **/
import { ticketDb } from './../../models';
import { cache } from './../domain/cache';
/** initialize implementation files **/
import initImpl from './impl';
/** provides services **/
const { availableSeats,
reserveSeat,
confirmSeat,
cancelSeat,
} = initImpl(redisConfig, cache, ...);
export const {
availableSeats,
reserveSeats,
confirmSeat,
cancelSeat
};
Move linkages to configuration.
{
"name": "booking",
"version": "1.0.0",
"description": "a ticket book...",
"author": "ns@work.com",
"plugin": {
"consumes": [
"db.Ticket",
"cache"
],
"provides": {
"booking@v1": "booking_v1.js",
"booking@v2": "booking_v2.js"
}
},
"scripts": {
"test": "mocha tests"
}
}
let cache, ticketDb;
let blockDuration;
module.exports = function setup(imports,
config) {
/** config values **/
blockDuration = config.blockDuration
|| 120;
/** imports **/
cache = imports['cache'];
ticketsDb = imports['db.Ticket'];
/** provides services **/
return {
availableSeats,
blockSeats,
confirmSeats,
cancelSeats,
};
}
function availableSeats(params) {
// do stuff
}
package.json
booking_v1.js
(Modules in code)
(Modules in config)
No 'import' between modules.
1. mongod
2. redis-server
3. Node app
4. Testcases
2. redis-server
4. Web App
1. mongod
3. Booking Service
Testcases
Booking Service
Ask Naval Saini
@navalsaini on twitter
Visit ArchieJs
github.com/archiejs