NeroCube / bookmark

Place some learning resources
0 stars 0 forks source link

Direct API to Database #381

Open NeroCube opened 1 year ago

NeroCube commented 1 year ago

Designing a highly available system can involve considering the possibility of having APIs directly interface with the database without implementing a queue in the middle. However, doing so comes with some benefits and risks.

Benefits:

  1. Simplification: Removing the queue system reduces system complexity, which can enhance system stability and maintainability.
  2. Improved efficiency: A queue system can introduce delays in a system, so directly interfacing with the database can enhance efficiency by eliminating the need for a queue application.
  3. Reduced single point of failure: A queue is an additional component, and if it fails, it can impact the entire system. Directly interfacing with the database can reduce the risk of a single point of failure.

Risks:

  1. Load imbalance: Directly interfacing with the database can lead to a high volume of requests being sent, causing load imbalance. This may lead to system performance degradation and unavailability.
  2. Increased system pressure: When a large volume of API requests enters the system, the database may be impacted by system pressure, leading to a decrease in efficiency and availability.

In conclusion, the decision to allow APIs to directly interface with the database without implementing a queue depends on the design goals and expected system loads. In high-load systems, using a queue system can help control the flow of requests and prevent overloading of the database. However, for simpler systems, direct interfacing with the database may be simpler and more efficient.

NeroCube commented 1 year ago

If it is found that the data volume is too large and a queue is required, we can design it as follows:

  1. Add a message queue between the API Server and Load Balancer to store all requests received from the API Server.
  2. When a request enters the message queue, it can be validated and converted first. If validation or conversion fails, the request can be rejected and an error message returned; otherwise, the request is placed in the message queue.
  3. Through the message queue, the request is sent to the destination Database and Splunk system for data writing and logging.
  4. After the destination system completes the data writing and logging, the result is returned to the message queue.
  5. When the API Server receives the returned result, it is returned to the requester. The following is a high-availability service architecture diagram using Queue:

The advantage of using a queue is that it can reduce the burden on the destination system when the data volume is too large and can prevent failures and losses during data transmission. In addition, the message queue can improve the scalability of the system because the number of message queues in the system can be increased or decreased as needed to meet the system's requirements.

NeroCube commented 1 year ago

實現優先佇列可以使用single queue或multiple queue,具體實現方法和優缺點如下:

Single Queue 在single queue的實現中,所有訊息都存放在同一個佇列中,但是每個訊息都會有一個priority字段,用於標記訊息的優先級。當處理訊息時,系統會從佇列中取出具有最高優先級的訊息進行處理。

優點:

缺點:

Multiple Queue 在multiple queue的實現中,我們可以創建多個佇列,每個佇列都專門處理一個特定優先級的訊息。例如,我們可以創建三個佇列,分別用於處理高、中、低三個優先級的訊息。

優點:

缺點:

綜上所述,single queue的優勢在於實現簡單,但在某些情況下可能會存在效率問題。而multiple queue雖然複雜度較高,但可以更好地管理不同優先級的訊息,提高系統的效率和性能。因此,在實際應用中需要根據具體情況來選擇使用哪種方法。