Sobes.tech
Junior — Middle

Can you give an example of implementing a system using microservices architecture?

sobes.tech AI

Answer from AI

Example of microservices architecture in Node.js:

Imagine an online store system divided into microservices:

  • User Service — responsible for registration and authentication.
  • Catalog Service — stores information about products.
  • Order Service — handles creation and management of orders.
  • Payment Service — responsible for payments.

Each service is a separate Node.js application with a REST API, communicating via HTTP or message queues.

Example of a simple microservice using Express:

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

app.post('/orders', (req, res) => {
  const order = req.body;
  // order creation logic
  res.status(201).send({message: 'Order created', orderId: 123});
});

app.listen(3000, () => console.log('Order Service running on port 3000'));

This approach allows scaling and developing services independently.

Can you give an example of implementing a system… - sobes.tech