System ArchitectureBackend Developer

What is microservice architecture and what are its advantages and disadvantages?

Pass interviews with Hintsage AI assistant

Answer.

Microservice architecture is an approach to building software systems where an application consists of small, isolated services, each responsible for a specific business task, developed and deployed independently of others.

Advantages:

  • Scalability: each service can be scaled independently.
  • Independent development: different teams can quickly develop individual services.
  • Fault tolerance: a failure in one service does not lead to the failure of the entire system.

Disadvantages:

  • Complex management: it requires setting up interactions, monitoring, and balancing.
  • Deployment complexity: coordinating many services can be challenging.
  • Increased communication overhead: services communicate over the network, which increases latency and requires reliable integration.

Example REST mockup of a microservice in Python (Flask):

from flask import Flask, jsonify app = Flask(__name__) @app.route('/user/<int:user_id>') def get_user(user_id): return jsonify({"user_id": user_id, "name": "Ivan"}) if __name__ == "__main__": app.run(port=5001)

Key features:

  • Each service is a standalone application.
  • It’s easy to introduce new technologies or languages for different services.
  • It requires taking into account network interaction errors and ensuring data consistency.

Trick questions.

Can microservices work on a single database?

This is permissible during the migration phase from a monolith, but it contradicts the ideology, as each service should store its own data separately to minimize dependencies and ensure independent development.

Is it mandatory to use Docker for microservice architecture?

No, Docker facilitates deployment and isolation, but microservices can be implemented without containerization, for example, using virtual machines or even separate physical servers.

What happens if the API contract between services is broken, but the CI/CD pipeline is all green?

A failure in the API contract will lead to interaction errors between services, which can only be detected through integration tests. A green build in CI/CD does not guarantee that different versions of services are compatible with each other.