Gate way, proxy,..

Link

Forward proxy và reverse proxy

API Gateway & Graph QL

Tất nhiên rồi, mình cùng phân tích sâu hơn về Kong Gateway và AWS API Gateway nhé.

Dưới đây là so sánh chi tiết giữa hai lựa chọn phổ biến này, đồng thời giải đáp thắc mắc của bạn về GraphQL.

So sánh chi tiết Kong Gateway và AWS API Gateway

Tiêu chí Kong Gateway (Open-Source & Enterprise) AWS API Gateway
Mô hình triển khai Linh hoạt: Có thể tự host (on-premise), trên bất kỳ nhà cung cấp đám mây nào (AWS, GCP, Azure), hoặc Kubernetes. Dịch vụ được quản lý (Managed Service): Chỉ chạy trên hạ tầng của AWS.
Chi phí Tiết kiệm hơn ở quy mô lớn: Bản open-source miễn phí. Bản Enterprise có phí license nhưng có thể rẻ hơn khi lưu lượng truy cập (traffic) rất lớn. Dễ dự đoán ở quy mô nhỏ: Trả tiền theo mức độ sử dụng (pay-as-you-go). Có bậc miễn phí (free-tier) khá hào phóng cho các dự án nhỏ và vừa.
Cộng đồng & Plugin Rất lớn và đa dạng: Hệ sinh thái plugin phong phú từ cộng đồng (miễn phí) và từ Kong (trả phí). Dễ dàng tùy chỉnh và mở rộng. Phụ thuộc vào AWS: Plugin và các tính năng mở rộng chủ yếu do AWS phát triển. Tích hợp sâu với các dịch vụ khác của AWS.
Vendor Lock-in Không: Vì là mã nguồn mở và có thể chạy ở bất cứ đâu, việc di chuyển sang nền tảng khác dễ dàng hơn. Cao: Rất khó để di chuyển sang nhà cung cấp khác nếu không thiết kế lại hệ thống.
Quản lý & Vận hành Cần chuyên môn: Đội ngũ của bạn phải tự cài đặt, cấu hình, giám sát và bảo trì. Đơn giản: AWS lo phần vận hành hạ tầng, bạn chỉ cần tập trung vào việc cấu hình API.

Export to Sheets


Khi nào nên chọn Kong Gateway? 🤔


Khi nào nên chọn AWS API Gateway? ☁️


Còn GraphQL thì sao? Nó có thay thế được API Gateway không? 🚀

Đây là một câu hỏi rất hay!

Câu trả lời ngắn gọn là: Không, GraphQL không thay thế API Gateway. Thay vào đó, chúng giải quyết các vấn đề khác nhau nhưng có thể hoạt động rất hiệu quả cùng nhau.

Kết hợp hoàn hảo: Bạn hoàn toàn có thể đặt một GraphQL server phía sau một API Gateway.

Mô hình phổ biến:

Client -> AWS API Gateway / Kong Gateway -> GraphQL Server (e.g., Apollo Server) -> Microservices / Databases

Trong mô hình này:

  1. API Gateway sẽ lo các vấn đề về bảo mật, rate limiting, logging.
  2. Sau khi request vượt qua được "cổng" này, nó sẽ được chuyển đến GraphQL Server.
  3. GraphQL Server sẽ phân tích truy vấn, gọi đến các microservice cần thiết để lấy dữ liệu, tổng hợp lại và trả về cho client một response duy nhất.

GRPC & Protobuf

The article discusses gRPC and Protocol Buffers (Protobuf) as options for communication between clients and servers or services within a microservice architecture.

gRPC (Google Remote Procedure Call) is an open-source framework developed by Google that allows applications running on different machines and using different programming languages to communicate effectively and reliably. It uses a client-server model for data transfer.

Protocol Buffers (Protobuf) is a data format also developed by Google. It is used to define data structures independently of language and platform. Protobuf uses .proto files to define these structures, and a compiler generates code for desired programming languages.

How they work together: gRPC uses Protobuf as the standard data format for all messages transferred between applications. This choice is highlighted as a key reason why gRPC data is very small in size and high in speed compared to traditional methods like JSON or XML. The source illustrates this by showing that a sample company data serialized with JSON is 102 bytes, while the same data serialized with Protobuf using a defined schema is only 50 bytes. The efficiency comes from Protobuf encoding data as binary values without including field names, relying on predefined field tags (like 1, 2, 3) for decoding.

Advantages of gRPC:

Considerations/Disadvantages of gRPC:

Comparison with REST: The source provides a small comparison:

Purpose and Use Case: gRPC is primarily used to help systems optimize bandwidth and speed when transferring information between clients/servers or services. While it offers significant benefits in these areas, particularly in large systems and microservice architectures, the decision to use gRPC requires considering trade-offs, such as the complexity of using HTTP/2, the difficulty in reading binary data, and the need for schema synchronization compared to simpler JSON-based methods.

Cú pháp cmd:

python -m grpc_tools.protoc --proto_path=. --python_out=. --grpc_python_out=. greet.proto

Enum

yield