[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2024-12-06。"],[[["\u003cp\u003eModular design enhances system flexibility and resilience by enabling the independent scaling, updating, and potential separation of components.\u003c/p\u003e\n"],["\u003cp\u003eBreaking down systems into independent modules with clear interfaces allows for targeted scaling, optimizing resource utilization and reducing costs by only provisioning necessary resources.\u003c/p\u003e\n"],["\u003cp\u003eModularity improves maintainability, making smaller, self-contained units easier to understand, debug, and update, which in turn leads to quicker development cycles and risk reduction.\u003c/p\u003e\n"],["\u003cp\u003eWhen designing for modularity, consider loose coupling, concurrency, and parallelism to build scalable and resilient applications, alongside balancing resource allocation and using well-defined interfaces.\u003c/p\u003e\n"],["\u003cp\u003eEmploying stateless models and selecting complementary technologies that support modularity can further improve scalability and recoverability, allowing the system to adapt without losing data.\u003c/p\u003e\n"]]],[],null,["# Promote modular design\n\nThis principle in the performance optimization pillar of the\n[Google Cloud Well-Architected Framework](/architecture/framework)\nprovides recommendations to help you promote a modular design.\nModular components and clear interfaces can enable flexible scaling,\nindependent updates, and future component separation.\n\nPrinciple overview\n------------------\n\nUnderstand the dependencies between the application components and the system\ncomponents to design a scalable system.\n\nModular design enables flexibility and resilience, regardless of whether a\nmonolithic or microservices architecture was initially deployed. By decomposing\nthe system into well-defined, independent modules with clear interfaces, you can\nscale individual components to meet specific demands.\n\nTargeted scaling can help optimize resource utilization and reduce costs in the\nfollowing ways:\n\n- Provisions only the necessary resources to each component, and allocates fewer resources to less-demanding components.\n- Adds more resources during high-traffic periods to maintain the user experience.\n- Removes under-utilized resources without compromising performance.\n\nModularity also enhances maintainability. Smaller, self-contained units are\neasier to understand, debug, and update, which can lead to faster development\ncycles and reduced risk.\n\nWhile modularity offers significant advantages, you must evaluate the potential\nperformance trade-offs. The increased communication between modules can\nintroduce latency and overhead. Strive for a balance between modularity and\nperformance. A highly modular design might not be universally suitable. When\nperformance is critical, a more tightly coupled approach might be appropriate.\nSystem design is an\n[iterative process](/architecture/framework/performance-optimization),\nin which you continuously review and refine your modular design.\n\nRecommendations\n---------------\n\nTo promote modular designs, consider the recommendations in the following\nsections.\n\n### Design for loose coupling\n\nDesign a\n[loosely coupled architecture](/architecture/microservices-architecture-refactoring-monoliths).\nIndependent components with minimal dependencies can help you build\n[scalable and resilient applications](/architecture/scalable-and-resilient-apps).\nAs you plan the boundaries for your services, you must consider the availability\nand scalability requirements. For example, if one component has requirements that\nare different from your other components, you can design the component as a standalone\nservice. Implement a plan for graceful failures for less-important subprocesses\nor services that don't impact the response time of the primary services.\n\n### Design for concurrency and parallelism\n\nDesign your application to support multiple tasks concurrently, like processing\nmultiple user requests or running background jobs while users interact with your\nsystem. Break large tasks into smaller chunks that can be processed at the same\ntime by multiple service instances. Task concurrency lets you use features like\nautoscaling to increase the resource allocation in products like the following:\n\n- [Compute Engine](/compute/docs/autoscaler)\n- [GKE](/spanner/docs/autoscaling-overview)\n- [BigQuery](/bigquery/docs/slots-autoscaling-intro)\n- [Spanner](/spanner/docs/autoscaling-overview)\n\n### Balance modularity for flexible resource allocation\n\nWhere possible, ensure that each component uses only the necessary resources\n(like memory, storage, and processing power) for specific operations. Resource\nover-allocation can result in unnecessary costs, while resource under-allocation can\ncompromise performance.\n\n### Use well-defined interfaces\n\nEnsure modular components communicate effectively through clear, standardized\ninterfaces (like APIs and message queues) to reduce overhead from translation\nlayers or from extraneous traffic.\n\n### Use stateless models\n\nA stateless model can help ensure that you can handle each request or interaction with\nthe service independently from previous requests. This model facilitates\nscalability and recoverability, because you can grow, shrink, or restart the\nservice without losing the data necessary for in-progress requests or\nprocesses.\n\n### Choose complementary technologies\n\nChoose technologies that complement the modular design. Evaluate programming\nlanguages, frameworks, and databases for their modularity support.\n\nFor more information, see the following resources:\n\n- [Re-architecting to cloud native](https://cloud.google.com/resources/rearchitecting-to-cloud-native)\n- [Introduction to microservices](/architecture/microservices-architecture-introduction)"]]