Micro-services introduction

Index

  • 12 factor app

12 factor app – it was documented by heroku based on their experiences with developing micro-services , it outlines set of best practises and guidelines while building the micro-services app

1. Codebase:

  • Principle: Maintain one codebase in version control, deploy multiple instances.
  • Implementation in Java:
    • Use Git for version control.
    • Organize code into a single repository.
    • Employ branching strategies for various environments (dev, staging, prod).
  • Why It’s Needed in Microservices:
    • Enables consistency across different environments.
    • Facilitates coordinated development and deployment of microservices.

2. Dependencies:

  • Principle: Explicitly declare and isolate dependencies.
  • Implementation in Java:
    • Use Maven or Gradle for dependency management.
    • Declare dependencies in project configuration.
    • Isolate dependencies to prevent conflicts.
  • Why It’s Needed in Microservices:
    • Ensures consistent dependencies across microservices.
    • Facilitates modular and independent development.

3. Config:

  • Principle: Store configuration in the environment.
  • Implementation in Java:
    • Utilize environment variables or configuration files.
    • Leverage Spring Boot configuration options.
    • Externalize sensitive configuration.
  • Why It’s Needed in Microservices:
    • Allows dynamic configuration changes without code modification.
    • Enhances portability across various deployment environments.

4. Backing Services:

  • Principle: Treat backing services as attached resources.
  • Implementation in Java:
    • Use connection pools and externalize configurations.
    • Employ abstractions provided by frameworks (e.g., Spring Data).
    • Avoid hardcoding credentials.
  • Why It’s Needed in Microservices:
    • Promotes independence of microservices from underlying infrastructure.
    • Simplifies integration with different backing services.

5. Build, Release, Run:

  • Principle: Separate build, release, and run processes.
  • Implementation in Java:
    • Use build tools for artifact creation.
    • Adopt continuous integration and deployment practices.
    • Separate build and deployment scripts.
  • Why It’s Needed in Microservices:
    • Enables efficient and controlled release processes.
    • Facilitates automation of deployment pipelines.

6. Processes:

  • Principle: Execute the app as stateless processes.
  • Implementation in Java:
    • Design stateless applications, especially in microservices.
    • Use frameworks like Spring Boot for stateless architectures.
  • Why It’s Needed in Microservices:
    • Enhances scalability and fault tolerance.
    • Allows for easy replication and distribution of microservices.

7. Port Binding:

  • Principle: Export services via port binding.
  • Implementation in Java:
    • Expose services through well-defined ports.
    • Use frameworks like Spring Boot for simplified port binding.
  • Why It’s Needed in Microservices:
    • Enables clear communication channels between microservices.
    • Enhances consistency and predictability in service access.

8. Concurrency:

  • Principle: Scale-out via the process model.
  • Implementation in Java:
    • Design applications for horizontal scalability.
    • Leverage Java’s concurrency utilities.
    • Use technologies like Kubernetes for orchestration.
  • Why It’s Needed in Microservices:
    • Facilitates handling increased loads by adding more instances.
    • Allows dynamic scaling based on demand.

9. Disposability:

  • Principle: Maximize robustness with fast startup and graceful shutdown.
  • Implementation in Java:
    • Optimize application startup time.
    • Use frameworks that support graceful shutdown.
    • Implement exception handling for robustness.
  • Why It’s Needed in Microservices:
    • Enables rapid deployment and updates.
    • Enhances the ability to recover from failures gracefully.

10. Dev/Prod Parity:

  • Principle: Keep development, staging, and production environments as similar as possible.
  • Implementation in Java:
    • Use containerization for environment consistency.
    • Apply infrastructure as code practices.
    • Utilize configuration management tools.
  • Why It’s Needed in Microservices:
    • Reduces the likelihood of bugs due to environment differences.
    • Facilitates smoother transitions between development and production.

11. Logs:

  • Principle: Treat logs as event streams.
  • Implementation in Java:
    • Use logging frameworks like SLF4J.
    • Send logs to centralized log management systems.
    • Structure logs for analysis.
  • Why It’s Needed in Microservices:
    • Aids in monitoring and debugging in a distributed environment.
    • Centralized logs provide a comprehensive view of the system.

12. Admin Processes:

  • Principle: Run admin/management tasks as one-off processes.
  • Implementation in Java:
    • Develop separate scripts or utilities for admin tasks.
    • Use frameworks like Spring Batch for batch processing.
  • Why It’s Needed in Microservices:
    • Allows for efficient and isolated execution of administrative tasks.
    • Prevents interference with regular application processes.

Embracing the 12 Factor App principles in Java-based microservices promotes consistency, scalability, and maintainability. It addresses challenges specific to distributed systems and ensures that microservices are developed and deployed in a cloud-native manner.

Published by

Unknown's avatar

sevanand yadav

software engineer working as web developer having specialization in spring MVC with mysql,hibernate

Leave a comment