Building a Micro-services based
ERP system
Using Node.js and MongoDB
Jerry M. Reghunadh
Senior Architect
http://capiot.com
{ “title” :“Topics” }
• Building our services - Decision process, Modeling, Referential Integrity
• Enabling service auto-discovery
• Validating request, response and data
• Performance and Throughput
• Our learnings – What we did right and what we did not.
{“short_intro”: “ERP”}
Core-Masters
Category Brand
Product Deal
Inventory and Warehouse
Warehouses Racks
BinsStock Adjustments
Finance and Commissions
AccountsPayments
ReceiptsCommissions
Third-party integrations
Wallet Recharge
Money Transfer Bill pay
Billing and Order Management
Orders Promotions
User Management
OTPAccess control
Logistics and Returns
RoutingReturns
Servicing
APIs are for the greater good!
“APIs are so
overrated”
President Frank Underwood
#FU2016
{“apis”:“very chatty!”}
Deal
Brand
Category
Product
1
2
3
4
1
2
3
4
{ “topic”:“Engineering Decisions”}
Low resource footprint
Low resource footprint Elasticity
• pm2
• Docker
Low resource footprint Elasticity
• pm2
• Docker
Monolingual
.js & json
Documents
JSON
Documents
JSON
Isn’t my data relational?
Why not SQL?
Documents
JSON
Flexible-Schema
Documents
JSON
Flexible-Schema Clustering + Sharding
{ “topic”:“Architecture”}
Cache
Micro-services
Logger
Big data store
Gateway
{ “topic”:“Architecture”}
Redis
Node.js + Mongo
Filebeat
Elasticsearch
Node.js
Portal (Angular)
API Gateway
{ “topic”:“APIs”}
Service 1
Service 2
Service N
...
Node.js
Express.js
Swagger.io
Mongoose.js
Passport.js
{ “api.framework”: “Swagger.io”}
Refer Open API Specification (OAS) https://github.com/OAI/OpenAPI-Specification
{ “odm”:“Mongoosejs”}
mongoosejs.com
Application layer
• Enforces schema
• Pre- and Post- hooks
• Promises
{“library”: “Swagger-mongoose-crud}
https://github.com/capiotsoftware/swagger-mongoose-crud
Create
Update
Delete
List
Get
Bulk Update
(and more)
MongoDB features as APIs
Create
Update
Delete
List
Get
GET http://localhost:8080/api/category/v1
PUT http://localhost:8080/api/category/v1/C2
GET http://localhost:8080/api/category/v1/C2
DELETE http://localhost:8080/api/category/v1/C2
POST http://localhost:8080/api/category/v1
db.categories
.find({name:{$regex: /as/}},{id:1, name:1})
.limit(10)
.skip(0)
.sort({name:-1})
{“question”: “How to auto-discover services?”}
Gateway
Alice
Bob
{“question”: “How to auto-discover services?”}
Gateway
Bob?
Alice
Bob
I want
Alice
Alice?
{“solution”: “IP-based config”}
Gateway
Alice
Bob
I want
Alice
Problem: Non-scalable!
{“solution”: “Look-up service”}
Gateway
Alice
Bob
I want
Alice
• Dynamic lookup solution
• Lightweight service
• Fast fetch
Cache
https://github.com/capiotsoftware/puttu-redis
{“issue”: “Security”}
?
• Censorship
• Privileged access
{“issue”: “Security”}
✓
• Censorship
• Privileged access
HTTPs
RBAC:
Role Based
Access
Control
{“rbac.define”: “How to set permissions”}
Service
name
Attributes
Roles
ERP Revisited
APIs
Adding	 features
Security
Scaling	and	Performance
Logging	 and	tracingCache
Micro-services
Logger
Big data store
Gateways
{“role”: “MongoDB”}
• Graphs $graphLookup
• Finding parent child relationships
• Finding optimal logistics route from route definitions, limited by hop count
{“role”: “MongoDB”}
• Geospatial queries
• Finding nearby hops to create routes.
• Offloaded most operations on the DB.
• Counters using $inc()
• Aggregate
• Graph lookup
• Auto expiring documents.
{“topic”:“Throughput and performance”}
{“topic”:“Throughput and performance”}
What we achieved: 330 tps
o 4Core 28GB
o 42 services on one machine
…
{“topic”:“Throughput and performance”}
What we achieved: 330 tps
o 4Core 28GB
o 42 services on one machine
…
Isn’t that low?
Not really!
Existing system: 150 tps
Projected: 300 tps in 2 years
{“topic”:“Throughput and performance”}
What we achieved: 330 tps
o 4Core 28GB
o 42 services on one machine
…
Isn’t that low?
Not really!
Existing system: 150 tps
Projected: 300 tps in 2 years
Consider other matrices
§ Talent acquisition
§ Feature turn around time
§ Agility of platform
{“question”: “What if I’m looking for more?”}
Might not be the right tool
{“question”: “What if I’m looking for more?”}
Might not be the right tool
Alternatives
{“question”: “What if I’m looking for more?”}
Might not be the right tool
Alternatives
Request: GET /
Response: Test response
9k tps
15k tps
{“question”: “What if I’m looking for more?”}
Might not be the right tool
Alternatives
Request: GET /
Response: Test response
9k tps
15k tps
What about DB?
{“question”: “What if I’m looking for more?”}
Might not be the right tool
Alternatives
Request: GET /
Response: Test response
9k tps
15k tps
What about DB?
+
5000 writes per secondHFT Solution
{“reflections”: “What we did right”}
ü Consistent with separation of collections
ü Know your DB
ü Create re-usable libraries/frameworks
ü Handle errors early
{“reflections”: “If time travel was possible…”}
o Understand: Write or Read intensive
o HTTP calls are expensive.
o Think of transactional data
Thankyou

Building a Microservices-based ERP System