# System Design

# Our System Design

## Introduction

To minimize the risk of spamming Midjourney, we have implemented several mechanisms to prevent system overload. These include rate limiting, queuing, concurrent handling, and load balancing.

## Rate Limiting

Rate limiting is enforced to prevent system overload. For general API endpoints, the rate limit is **1 request per 3 seconds**. For the progress checking endpoint: [message](https://docs.imaginepro.ai/api-215981214), the rate limit is **10 requests per second**.

**Note**: Our rate limiting is primarily a mechanism to deter spamming. Normally, the rate limit will not introduce additional waiting time for completing Midjourney jobs, as a typical job takes significantly longer than 3 seconds to complete, and user can send another job during this period.

## Queueing System

We employ a queuing system for each account to avoid overloading both our system and Discord. New jobs are added to the queue and processed in a first-come, first-served basis. The number of queues available to you depends on your subscription plan:

- For [Trial, Starter, Grown, Professional, Business](https://www.imaginepro.ai/pricing) plan, you have **one queue**.
- For [DIY](https://www.imaginepro.ai/pricing) plan, you have **one queue per connected Discord account**.

### Sample:

In this scenario, the user has connected only 1 Discord account, and the Midjourney plan the user is subscribed to supports 3 concurrent jobs. The user has sent 8 jobs in total. Our queue system sends the first X number of jobs (X is the [concurrent limit](#concurrent-limiting), in this example, 3) (`Job1`, `Job2`, `Job3`) to Discord, and will keep tracking the status of these jobs.

Since our system knows the number of concurrent jobs supported by the user's Midjourney plan when connecting the Discord account, with 3 jobs (`Job1`, `Job2`, `Job3`) in progress, Our system will hold the remaining jobs (`Job4` to `Job8`) until a slot becomes available in Discord.

When `Job1` is completed, our system will send `Job4` to Discord. When `Job2` is completed, our system will send `Job5` to Discord. When `Job3` is completed, our system will send `Job6` to Discord. And so on.


![queue1.webp](https://api.apifox.com/api/v1/projects/5160896/resources/465568/image-preview)

![queue2.webp](https://api.apifox.com/api/v1/projects/5160896/resources/465569/image-preview)


## Concurrent Limiting

We have implemented a concurrent job limit to Midjourney in Discord overload. The number of the maximum concurrent limit depends on your subscription plan:

- For [Trial, Starter, Grown](https://www.imaginepro.ai/pricing) plan, the concurrent limit is **8**.
- For [Professional, Business](https://www.imaginepro.ai/pricing) plan, the concurrent limit is **10**.
- For [DIY](https://www.imaginepro.ai/pricing) plan plan, the concurrent limit is **3 or 12** depending on your Midjourney subscription plan (Basic and Standard Midjourney plan is 3, and Pro and Mega Midjourney plan is 12).

You can change the concurrent limit in the [setup](https://www.imaginepro.ai/dashboard/setup) page, where you link your Discord account. Comparing your Midjourney plan's concurrency limit, we recommend using a slightly smaller number for our concurrent limit, to allow some buffering in Discord and avoid keep flooding your connected Discord account, which may increase the ban risk.

## Load Balancing

Our system includes built-in load balancing when [linking multiple Discord accounts](https://docs.imaginepro.ai/doc-5155921). The load balancer distributes jobs among these accounts in a round-robin manner. This ensures that the load is evenly distributed among the linked accounts.

So if you linked multiple Discord accounts, and couldn't find your specific job in one Discord account, maybe try the other ones.

