Khám Phá Kiến Trúc Microservices và Lợi Ích Của Nó Trong Phát Triển Phần Mềm

Tài liệu nghiên cứu Microservice architectures, tổng hợp lý thuyết và thực hành, cung cấp kiến thức chuyên sâu về ., phục vụ nghiên cứu và ứng dụng thực tiễn

Trường đại học

codecentric AG

Chuyên ngành

Kiến Trúc Microservices

Người đăng

Ẩn danh

Thể loại

bài giảng

2025

53
7
0

Phí lưu trữ

30 Point

Mục lục chi tiết

1. About me

2. Agenda

3. The Pain

5. Software Monolith

6. Problems of Software Monoliths

7. Layered Systems

8. Problems of Layered Systems

9. Growing systems beyond the limits

10. Therefore, Microservices

12. Underlying principle

13. More specifically

14. Independent Deployability is key

15. Independent code base

16. Independent technology stacks

17. Independent Scaling

18. Independent evolution of Features

19. Stable Interfaces – standardized communication

20. Stable Interfaces: HTTP, JSON, REST

22. HTTP

23. JSON

24. REST

25. REST Architectural Constraints

26. HATEOAS example in JSON

27. Stable Interfaces

28. Characteristics Componentization via Services

30. Favors Cross-Functional Teams

31. Decentralized Governance

32. Decentralized Data Management

33. Infrastructure Automation

34. Comparisons with Precursors Service-Oriented Architecture

36. Service-Oriented Architecture

37. Component-Based Software Engineering

38. Challenges Fallacies of Distributed Computing

40. Microservices Prerequisites

41. Evolving interfaces correctly

42. API Compatibility

43. Forward compatibility through REST and JSON

44. Compatibility and Versioning

45. REST API Versioning

46. REST API Versioning

47. Further Challenges

48. Conclusion Microservices: just …?

Tóm tắt

I. Tổng Quan Về Kiến Trúc Microservices Giải Pháp Tối Ưu Cho Phát Triển Phần Mềm

Kiến trúc Microservices đang trở thành một xu hướng quan trọng trong phát triển phần mềm hiện đại. Nó cho phép các nhóm phát triển xây dựng và triển khai các dịch vụ độc lập, giúp tăng cường khả năng mở rộng và tính linh hoạt. Mô hình này không chỉ giúp giảm thiểu sự phức tạp mà còn cải thiện hiệu suất và khả năng bảo trì của hệ thống. Theo Dr. Andreas Schroeder, việc áp dụng kiến trúc Microservices có thể giúp các tổ chức phát triển phần mềm một cách hiệu quả hơn.

1.1. Định Nghĩa Kiến Trúc Microservices

Kiến trúc Microservices là một phương pháp phát triển phần mềm, trong đó ứng dụng được chia thành nhiều dịch vụ nhỏ, độc lập. Mỗi dịch vụ thực hiện một chức năng cụ thể và có thể được triển khai riêng biệt. Điều này giúp tăng cường khả năng mở rộng và giảm thiểu rủi ro khi triển khai.

1.2. Lợi Ích Của Kiến Trúc Microservices

Một trong những lợi ích lớn nhất của kiến trúc Microservices là khả năng phát triển và triển khai nhanh chóng. Các nhóm có thể làm việc song song trên các dịch vụ khác nhau mà không làm ảnh hưởng đến nhau. Điều này không chỉ tiết kiệm thời gian mà còn giảm thiểu rủi ro trong quá trình phát triển.

II. Vấn Đề Trong Phát Triển Phần Mềm Truyền Thống Tại Sao Cần Microservices

Phát triển phần mềm truyền thống thường gặp phải nhiều thách thức, đặc biệt là khi quy mô dự án tăng lên. Các ứng dụng lớn thường được xây dựng dưới dạng monolith, dẫn đến việc khó khăn trong việc bảo trì và mở rộng. Theo nghiên cứu, các hệ thống này thường gặp phải vấn đề về hiệu suất và khả năng mở rộng. Kiến trúc Microservices được thiết kế để giải quyết những vấn đề này.

2.1. Những Thách Thức Của Hệ Thống Monolith

Hệ thống monolith thường có mã nguồn lớn và phức tạp, khiến cho việc phát triển và bảo trì trở nên khó khăn. Thời gian xây dựng và kiểm thử kéo dài, và việc triển khai các thay đổi mới có thể gây ra rủi ro lớn cho toàn bộ hệ thống.

2.2. Tại Sao Microservices Là Giải Pháp Tối Ưu

Kiến trúc Microservices cho phép các nhóm phát triển làm việc độc lập, giảm thiểu sự phụ thuộc lẫn nhau. Điều này không chỉ giúp tăng tốc độ phát triển mà còn cải thiện khả năng phản hồi với các yêu cầu thay đổi từ thị trường.

III. Phương Pháp Triển Khai Microservices Các Bước Cần Thiết

Để triển khai kiến trúc Microservices, các tổ chức cần thực hiện một số bước quan trọng. Đầu tiên, cần xác định các dịch vụ cần thiết và cách chúng sẽ tương tác với nhau. Tiếp theo, việc lựa chọn công nghệ phù hợp cho từng dịch vụ là rất quan trọng. Cuối cùng, cần thiết lập quy trình triển khai tự động để đảm bảo tính nhất quán và hiệu quả.

3.1. Xác Định Các Dịch Vụ Cần Thiết

Việc xác định các dịch vụ cần thiết là bước đầu tiên trong quá trình triển khai Microservices. Các dịch vụ nên được thiết kế để thực hiện các chức năng cụ thể và có thể hoạt động độc lập.

3.2. Lựa Chọn Công Nghệ Phù Hợp

Mỗi dịch vụ trong kiến trúc Microservices có thể sử dụng công nghệ khác nhau. Việc lựa chọn công nghệ phù hợp giúp tối ưu hóa hiệu suất và khả năng mở rộng của từng dịch vụ.

3.3. Thiết Lập Quy Trình Triển Khai Tự Động

Quy trình triển khai tự động là rất quan trọng trong kiến trúc Microservices. Nó giúp đảm bảo rằng các dịch vụ được triển khai một cách nhất quán và nhanh chóng, giảm thiểu rủi ro trong quá trình phát triển.

IV. Ứng Dụng Thực Tiễn Của Microservices Trong Doanh Nghiệp

Nhiều doanh nghiệp lớn đã áp dụng kiến trúc Microservices để cải thiện quy trình phát triển phần mềm của họ. Ví dụ, Amazon và Netflix đã sử dụng Microservices để xây dựng các hệ thống linh hoạt và có khả năng mở rộng cao. Những ứng dụng này không chỉ giúp cải thiện hiệu suất mà còn tăng cường khả năng phục vụ khách hàng.

4.1. Trường Hợp Của Amazon

Amazon đã áp dụng kiến trúc Microservices để phát triển các dịch vụ độc lập, cho phép họ mở rộng quy mô một cách linh hoạt. Điều này giúp Amazon phục vụ hàng triệu khách hàng mà không gặp phải vấn đề về hiệu suất.

4.2. Trường Hợp Của Netflix

Netflix sử dụng kiến trúc Microservices để cung cấp dịch vụ streaming cho hàng triệu người dùng. Hệ thống của họ được thiết kế để có thể mở rộng và phục vụ hàng triệu yêu cầu đồng thời mà không gặp phải sự cố.

V. Kết Luận Tương Lai Của Kiến Trúc Microservices

Kiến trúc Microservices đang trở thành một phần quan trọng trong phát triển phần mềm hiện đại. Với khả năng mở rộng và tính linh hoạt cao, nó hứa hẹn sẽ tiếp tục phát triển và được áp dụng rộng rãi trong tương lai. Các tổ chức cần chuẩn bị để thích ứng với xu hướng này để duy trì tính cạnh tranh trên thị trường.

5.1. Xu Hướng Tương Lai Của Microservices

Dự báo rằng kiến trúc Microservices sẽ tiếp tục phát triển và trở thành tiêu chuẩn trong phát triển phần mềm. Các công nghệ mới như KubernetesDocker sẽ hỗ trợ cho việc triển khai và quản lý các dịch vụ này.

5.2. Lời Khuyên Cho Các Tổ Chức

Các tổ chức nên bắt đầu tìm hiểu và áp dụng kiến trúc Microservices để cải thiện quy trình phát triển phần mềm của họ. Việc đầu tư vào công nghệ và đào tạo nhân viên là rất cần thiết để tận dụng tối đa lợi ích của mô hình này.

10/07/2025

Trích đoạn nội dung tài liệu

Microservice Architectures Dr. Andreas Schroeder 1 About me 250+ staff 12 offfices (9 in Germany) Experts for developing custom IT solutions Involvement in the IT community via • twitter Dr. Andreas Schroeder • github codecentric AG • meetup Elsenheimerstr 55A • … 80687 München andreas.de 2 Agenda • The Pain • Therefore, Microservices • Stable Interfaces: HTTP, JSON, REST • Characteristics • Comparison with Precursors • Challenges • With special focus on Service Versioning • Conclusion 3 The Pain Observed problems • Area of consideration • Web systems • Built collaboratively by several development teams • With traffic load that requires horizontal scaling (i. load balancing across multiple copies of the system) • Observation • Such systems are often built as monoliths or layered systems (JEE) 5 Software Monolith A Software Monolith • One build and deployment unit • One code base • One technology stack (Linux, JVM, Tomcat, Libraries) Benefits • Simple mental model for developers • one unit of access for coding, building, and deploying • Simple scaling model for operations • just run multiple copies behind a load balancer 6 Problems of Software Monoliths • Huge and intimidating code base for developers • Development tools get overburdened • refactorings take minutes • builds take hours • testing in continuous integration takes days • Scaling is limited • Running a copy of the whole system is resource-intense • It doesn’t scale with the data volume out-of-the-box • Deployment frequency is limited • Re-deploying means halting the whole system • Re-deployments will fail and increase the perceived risk of deployment 7 Layered Systems A layered system decomposes a monolith into layers Presentation • Usually: presentation, logic, data access • At most one technology stack per layer • Presentation: Linux, JVM, Tomcat, Libs, EJB client, JavaScript Logic • Logic: Linux, JVM, EJB container, Libs • Data Access: Linux, JVM, EJB JPA, EJB container, Libs Data Access Benefits • Simple mental model, simple dependencies • Simple deployment and scaling model DB 8 Problems of Layered Systems • Still huge codebases (one per layer) • … with the same impact on development, building, and deployment • Scaling works better, but still limited • Staff growth is limited: roughly speaking, one team per layer works well • Developers become specialists on their layer • Communication between teams is biased by layer experience (or lack thereof) 9 Growing systems beyond the limits • Applications and teams need to grow beyond the limits imposed by monoliths and layered systems, and they do – in an uncontrolled way.

• Large companies end up with landscapes of layered systems that often interoperate in undocumented ways. • These landscapes then often break in unexpected ways. How can a company grow and still have a working IT architecture and vision? • Observing and documenting successful companies (e. Amazon, Netflix) lead to the definition of microservice architecture principles.

10 Therefore, Microservices History • 2011: First discussions using this term at a software architecture workshop near Venice • May 2012: microservices settled as the most James Lewis appropriate term • March 2012: “Java, the Unix Way” at 33rd degree by James Lewis • September 2012: “µService Architecture“ at Fred George Baruco by Fred George • All along, Adrian Cockroft pioneered this style at Netflix as “fine grained SOA” http://martinfowler.com/articles/microservices.html#footnote-etymology Adrian Cockroft 12 Underlying principle On the logical level, microservice architectures are defined by a functional system decomposition into manageable and independently deployable components • The term “micro” refers to the sizing: a microservice must be manageable by a single development team (5-9 developers) • Functional system decomposition means vertical slicing (in contrast to horizontal slicing through layers) • Independent deployability implies no shared state and inter-process communication (often via HTTP REST-ish interfaces) 13 More specifically • Each microservice is functionally complete with • Resource representation • Data management • Each microservice handles one resource (or verb), e. • Clients • Shop Items • Carts • Checkout Microservices are fun-sized services, as in “still fun to develop and deploy” 14 Independent Deployability is key It enables separation and independent evolution of • code base • technology stacks • scaling • and features, too 15 Independent code base Each service has its own software repository • Codebase is maintainable for developers – it fits into their brain • Tools work fast – building, testing, refactoring code takes seconds • Service startup only takes seconds • No accidental cross-dependencies between code bases 16 Independent technology stacks Each service is implemented on its own technology stacks • The technology stack can be selected to fit the task best • Teams can also experiment with new technologies within a single microservice • No system-wide standardized technology stack also means • No struggle to get your technology introduced to the canon • No piggy-pack dependencies to unnecessary technologies or libraries • It‘s only your own dependency hell you need to struggle with  • Selected technology stacks are often very lightweight • A microservice is often just a single process that is started via command line, and not code and configuration that is deployed to a container. 17 Independent Scaling Each microservice can be scaled independently • Identified bottlenecks can be addressed directly Netflix • Data sharding can be applied to microservices as needed • Parts of the system that do not represent bottlenecks can remain simple and un-scaled functional decomp. Scaling Cube JEE Pet Store horizontal & vertical 18 Independent evolution of Features Microservices can be extended without affecting other services • For example, you can deploy a new version of (a part of) the UI without re-deploying the whole system • You can also go so far as to replace the service by a complete rewrite But you have to ensure that the service interface remains stable 19 Stable Interfaces – standardized communication Communication between microservices is often standardized using • HTTP(S) – battle-tested and broadly available transport protocol • REST – uniform interfaces on data as resources with known manipulation means • JSON – simple data representation format REST and JSON are convenient because they simplify interface evolution (more on this later) 20 Stable Interfaces: HTTP, JSON, REST HTTP Example GET / HTTP/1.de Connection: keep-alive Cache-Control: max-age=0 Accept: text/html,application/xhtml+xml,application/xml;q=0.8 User-Agent: Mozilla/5.36 Accept-Encoding: gzip,deflate Accept-Language: de-DE,de;q=0.1 200 OK Date: Tue, 21 Oct 2014 06:34:29 GMT Server: Apache/2.29 (Amazon) Cache-Control: no-cache, must-revalidate, max-age=0 Content-Encoding: gzip Content-Length: 8083 Connection: close Content-Type: text/html; charset=UTF-8 22 HTTP • Available verbs GET, POST, PUT, DELETE (and more) • Safe verbs: GET (and others, but none of the above) • Non-idempotent: POST (no other verb has this issue) • Mechanisms for • caching and cache control • content negotiation • session management • user agent and server identification • Status codes in response (200, 404, etc) for information, success, redirection, client error, server error • Rich standardized interface for interacting over the net 23 JSON • Minimal and popular data representation format • Schemaless in principle, but can be validated if need be Example of two bank accounts: [{ "number" : 12345, "balance" : -20.00, "currency" : "EUR" }, { "number" : 12346, "balance" : 120.00, "currency" : "USD" }] json.org 24 REST • REST is an architectural style for systems built on the web.

It consists of a set of coordinated architectural constraints for distributed hypermedia systems. • REST describes how to build systems on battle-tested protocols and standards that are already out there (like HTTP) • REST describes the architectural ideas behind HTTP, and how HTTP can be used to do more than serving static web content 25 REST Architectural Constraints • Client-Server: Separation of logic from user interface • Stateless: no client context on the server • Cacheable: reduce redundant interaction between client and server • Layered System: intermediaries may relay communication between client and server (e. for load balancing) • Code on demand: serve code to be executed on the client (e. JavaScript) • Uniform interface • Use of known HTTP verbs for manipulating resources • Resource manipulation through representations which separated from internal representations • Hypermedia as the engine of application state (HATEOAS): the response contains all allowed operations and the resource identifiers needed to trigger them 26 HATEOAS example in JSON Resource representation { "number" : 12345, "balance" : -20.00, "currency" : "EUR", "links" : [ { relation name (known by clients) "rel" : "self", "href" : "https://bank.com/account/12345" }, { "rel" : "deposit", "href" : "https://bank.com/account/12345/deposit" } ] } URI for operation 27 Stable Interfaces • HTTP offers a rich set of standardized interaction mechanisms that still allow for scaling • JSON offers a simple data format that can be (partially) validated • REST provides principles and ideas for leveraging HTTP and JSON to build evolvable microservice interfaces Be of the web, not behind the web Ian Robinson 28 Characteristics Componentization via Services • Interaction mode: share-nothing, cross-process communication • Independently deployable (with all the benefits) • Explicit, REST-based public interface • Sized and designed for replaceability • Upgrading technologies should not happen big-bang, all-or-nothing-style • Downsides • Communication is more expensive than in-process • Interfaces need to be coarser-grained • Re-allocation of responsibilities between services is harder 30 Favors Cross-Functional Teams • Line of separation is along functional boundaries, not along tiers Presentation Logic VS Data Access DB 31 Decentralized Governance Principle: focus on standardizing the relevant parts, and leverage battle-tested standards and infrastructure Treats differently • What needs to be standardized • Communication protocol (HTTP) • Message format (JSON) • What should be standardized • Communication patterns (REST) • What doesn‘t need to be standardized • Application technology stack 32 Decentralized Data Management • OO Encapsulation applies to services as well • Each service can choose the persistence solution that fits best its • Data access patterns • Scaling and data sharding requirements • Only few services really need enterprisey persistence 33 Infrastructure Automation • Having to deploy significant number of services forces operations to automate the infrastructure for • Deployment (Continuous Delivery) • Monitoring (Automated failure detection) • Managing (Automated failure recovery) • Consider that: • Amazon AWS is primarily an internal service • Netflix uses Chaos Monkey to further enforce infrastructure resilience 34 Comparisons with Precursors Service-Oriented Architecture ORCHESTRATION SERVICE DATA 36 Service-Oriented Architecture SOA systems also focus on functional decomposition, but • services are not required to be self-contained with data and UI, most of the time the contrary is pictured.

• It is often thought as decomposition within tiers, and introducing another tier – the service orchestration tier In comparison to microservices • SOA is focused on enabling business-level programming through business processing engines and languages such as BPEL and BPMN • SOA does not focus on independent deployment units and its consequences • Microservices can be seen as “SOA – the good parts” 37 Component-Based Software Engineering Underlying functional decomposition principle of microservices is basically the same. Additionally, the following similarities and differences exist: • State model • Many theoretical component models follow the share-nothing model • Communication model • Component technologies often focus on simulating in-process communication across processes (e. Java RPC, OSGi, EJB) • Microservice communication is intra-process, serialization-based • Code separation model • Component technologies do require code separation • Components are often developed in a common code repository • Deployment model • Components are often thought as being deployed into a uniform container 38 Challenges Fallacies of Distributed Computing Essentially everyone, when they first build a distributed application, makes the following eight assumptions. All prove to be false in the long run and all cause big trouble and painful learning experiences.

Nội dung được bảo vệ bản quyền — Tải xuống đầy đủ

Tài liệu "Kiến Trúc Microservices: Giải Pháp Tối Ưu Cho Phát Triển Phần Mềm" cung cấp cái nhìn sâu sắc về kiến trúc microservices, một phương pháp phát triển phần mềm hiện đại giúp tối ưu hóa quy trình và nâng cao khả năng mở rộng của ứng dụng. Tác giả nhấn mạnh rằng việc chia nhỏ ứng dụng thành các dịch vụ độc lập không chỉ giúp dễ dàng quản lý và bảo trì mà còn tăng cường khả năng phát triển song song, từ đó rút ngắn thời gian ra mắt sản phẩm.

Độc giả sẽ tìm thấy nhiều lợi ích từ việc áp dụng kiến trúc microservices, bao gồm khả năng linh hoạt trong việc thay đổi công nghệ, cải thiện hiệu suất và khả năng phục hồi của hệ thống. Để mở rộng thêm kiến thức về các phương pháp phát triển phần mềm, bạn có thể tham khảo tài liệu Đề tài nghiên cứu khoa học lập trình hướng agent, nơi cung cấp cái nhìn khác về lập trình hướng agent và cách nó có thể được áp dụng trong các hệ thống phức tạp.

Khám phá thêm những tài liệu này sẽ giúp bạn nắm bắt được nhiều khía cạnh khác nhau trong lĩnh vực phát triển phần mềm, từ đó nâng cao kỹ năng và hiểu biết của mình.