Micro-Services Mechano
The core concepts and related design patterns
The core concepts and related design patterns
Mecchano model represents the collaboration between set of micro-services design patterns to achieve specific non-functional requirements, which you are looking to achieve within your solution, so, no one-only design pattern will be used, but collaborative work will take place.
It's custom combination according to the non-functional requirements that you need to achieve.
Configuration: to have NFR solution configurability, and extendibility, which you will need to implement:
External configuration design pattern
Realtime reconfiguration design pattern
Cache aside design pattern
Publisher subscriber design pattern
Performance: In order to have NFR fast responding solution, which requires implementing the following design patterns:
Cache aside
Materialized views
Indexed table
Resiliency, in order to achieve NFR for consistency, and stability of the solution
Security in order to have a secure solution
UX: to improve the user experience.
1. External Configuration
Concept: Store application configuration outside the code (files, environment variables, or config servers).
Use Case: Multi-environment deployments, microservices, CI/CD pipelines.
Best Practices:
Keep secrets separate (use vaults or KMS).
Use consistent formats (YAML, JSON, TOML).
Version control non-sensitive configs.
2. Realtime Reconfiguration
Concept: Ability to update configuration at runtime without restarting the service.
Use Case: Dynamic feature toggles, tuning parameters in production, traffic management.
Best Practices:
Validate changes before applying.
Ensure atomicity and thread-safety.
Audit configuration changes for rollback.
3. Publisher-Subscriber (Pub/Sub) for Config
Concept: Config changes are broadcast to interested services/components via messaging.
Use Case: Large-scale distributed systems where multiple services need to react to config changes instantly.
Best Practices:
Decouple producers and consumers.
Ensure idempotency for repeated events.
Monitor propagation latency and consistency.
1. Indexed Table
Concept: Add indexes to database tables on frequently queried columns to speed up lookups.
Use Case: Large tables where searches, joins, or range queries are common.
Best Practices:
Index columns used in WHERE, JOIN, ORDER BY.
Avoid excessive indexing (slows writes).
Use composite indexes carefully when multiple columns are queried together.
2. Cache-Aside (Lazy Loading)
Concept: Application checks cache first; if miss, fetch from DB, then populate cache.
Use Case: Frequently read but rarely updated data.
Best Practices:
Set TTLs to avoid stale data.
Handle cache invalidation carefully.
Consider write-through if updates are frequent.
3. Materialized View
Concept: Precompute and store the results of expensive queries for fast access.
Use Case: Complex aggregations, reporting dashboards, OLAP workloads.
Best Practices:
Refresh periodically or on-demand depending on data volatility.
Monitor storage cost and query patterns.
Use incremental refresh if supported.
Standards/References:
SQL standard: CREATE MATERIALIZED VIEW; Oracle, PostgreSQL, SQL Server implementations.
Retry Pattern: Automatically re-attempts a failed operation due to transient issues (e.g., network glitches), improving reliability without manual intervention. It should include backoff strategies to avoid overwhelming dependent services.
Circuit Breaker: Prevents repeated calls to a failing service by “opening the circuit” after a threshold, allowing the system to recover and protecting overall stability. It switches between closed, open, and half-open states.
Scheduler Agent: Executes tasks asynchronously or at predefined intervals, decoupling time-dependent operations from real-time flows. It improves resilience by handling retries, delayed processing, and workload smoothing.
Transaction Compensation: Handles failures in distributed transactions by executing compensating actions to undo completed steps, ensuring eventual consistency instead of strict rollback across services.
1. Federated Identity
Concept: Allows users to authenticate across multiple systems using a single identity provider (IdP).
Use Case: Single Sign-On (SSO) for enterprise apps or third-party services.
Best Practices:
Use standards like SAML 2.0, OAuth 2.0, or OpenID Connect.
Minimize user credentials stored locally.
Implement proper token validation and expiration.
2. Valet Key
Concept: Issue time-limited, scoped tokens granting access to specific resources without exposing full credentials.
Use Case: Securely allow clients or apps to access storage (e.g., cloud blobs) for a short time.
Best Practices:
Limit scope (read/write) and duration.
Revoke or expire keys automatically.
Use secure transport (HTTPS) for token delivery.
Consists of the previously mentioned configuration, performance, and resiliency design patterns, moreover the security design patterns as following:
1. Configuration design patterns: enhance maintainability and response to change.
2. Performance design patterns: enhance response time, and time to finish the service.
3. Resiliency design patterns: Enhance stability, and business continuity
4. Security design patterns: Enhance solution security to meet CIA security principles
Dr. Ghoniem Lawaty
Tech Evangelist @TechHuB Egypt