# Rake Deduction Logic

I am writing an Online Poker Game and I was wondering about how the Rake will be deducted for each hand in a cash game.

I know there is rake percentage and rakecap concept and the rake is calculated based on pot size and if that amount is greater than rakecap we take rakecap amount, in short, we take the minimum of calculated rake and rakecap.

My question is with how to choose the rake percentage and rake cap values because there are two types of rake percentages I see 1 is rake percentage and then there is rake percentage(< 3) Which is actually the rake that needs to be considered when the number of players is less than 3.

Consider a scenario in which there are 4 players in the starting of hand:
In preflop 1 player goes all-in and others call leading to the main pot
In flop another player goes all-in and 1 player folds and 1 player call leading to side pot 1
No action is performed in turn and river

Now at showdown, we have side pot 1 in which 2 players are available and the main pot in which we have 4 players

My question is should I select Normal Rake Percentage and Rake Cap for Main Pot (which has 4 players) and Rake Percentage Head's Up for Side Pot 1 (which has 2 players) OR Should I select only 1 rake percentage i.e normal rake percentage for both the pots since there are 4 players at the time of the start of the hand.

Rake percentage is based on the number of players at the starting of the hand or number of players in the pot?

Thanks