Group balances/plans

29 views
Skip to first unread message

Domen

unread,
Jan 23, 2026, 4:10:44 AM (10 days ago) Jan 23
to CGRateS
Greetings,

I'm thinking of implementing group like balances. But I'm not sure how to  tackle this problem. 

So lets imagine something like a family plan with 1000 units. We connect this plan to 3 accounts, these 3 accounts then use these 1000 units. Right now when I connect these 3 accounts to a plan they each get 1000 units. I could solve it by setting each of the accounts units to 333, but again this limits the accounts. What if 1 account uses 400, that means there is 600 left for the other 2 accounts?

How can I solve this problem?

Best regards,
Domen

Domen

unread,
Jan 23, 2026, 4:34:57 AM (10 days ago) Jan 23
to CGRateS
One of the ideas I had is to create another account GROUP_ACCOUNT to which I would assign 1000 units. Then using attributes I would change the incoming usage to the 3 accounts to be the GROUP_ACCOUNT. But I'm not sure this is the way.

petek, 23. januar 2026 ob 10:10:44 UTC+1 je oseba Domen napisala:

Marcin Kowalczyk

unread,
Jan 23, 2026, 4:49:04 AM (10 days ago) Jan 23
to CGRateS
Try to use SharedGroup - general idea is here https://groups.google.com/g/cgrates/c/MOPv9QWsDFw/m/OgbxJ4nRBgAJ ;) 

Domen

unread,
Jan 23, 2026, 8:39:30 AM (10 days ago) Jan 23
to CGRateS
Thank you for that idea
.
I tried what you recommended, but I got stuck, that my group is never found (CGRateS <6514788> [1673231]: Could not get shared group: GROUP_A) I added it to the tp_shared_groups table as well and reloaded the service/data. 

Here are some requests I made:
Make the accounts:
{
"method": "APIerSv1.SetAccount",
"params": [
{
"Tenant": "default",
"Account": "TEST_ACCOUNT1"
}
]
}

{
"method": "APIerSv1.SetAccount",
"params": [
{
"Tenant": "default",
"Account": "TEST_ACCOUNT2"
}
]
}

Set the balances:
{
"method": "ApierV1.SetBalance",
"params": [
{
"Tenant": "default",
"Account": "TEST_ACCOUNT1",
"BalanceType": "*data",
"Balance": {
"ID": "GROUP_BUCKET_1000",
"Value": 1000,
"Categories": "*any",
"Weight": 10,
"SharedGroups":"GROUP_A"
}
}
],
"id": 6
}

Send the CDR:
{
"method": "CDRsV1.ProcessCDR",
"params": [
{
"TPid": "default",
"ToR": "*data",
"Tenant": "default",
"OriginID": "test2",
"Source": "*sessions",
"RequestType": "*postpaid",
"Account": "TEST_ACCOUNT1",
"Category": "*any",
"Subject": "",
"Destination": null,
"SetupTime": "2025-10-10T13:01:53.668+01:00",
"AnswerTime": "2025-10-10T13:01:53.668+01:00",
"Usage": 100
}
]
}

Now the account does have the balance (for now only 1).
But every CDR I sent I get the same error.

Thanks in advance.
petek, 23. januar 2026 ob 10:49:04 UTC+1 je oseba kow...@gmail.com napisala:

Armir Veliaj

unread,
Jan 23, 2026, 11:06:49 AM (10 days ago) Jan 23
to CGRateS
Hi Domen,

Using SharedGroup is possible as we already have that as an option implemented, but you need to be aware that it could have a small potential issue, especially during high traffic situations. For example, in case of two accounts using the same balance, if one account points toward a balance in another account and that balance in another account points back to this one, that's a deadlock.

As a safer option, you can make use of Attributes where that deadlock won't happen, so we would recommend this option to avoid facing the issue and the complexity of the SharedGroup scenario.

Hope it helps!

Thanks,
Armir

Domen

unread,
Jan 26, 2026, 2:40:46 AM (7 days ago) Jan 26
to CGRateS
Hey Armir,

thank you for this insight, I would mostly have the case where, the shared group would have 1 account with the balance, and all other accounts (and the account with the balance) would point and deduct from that balance. If I'm understanding this correctly, it should not cause a deadlock? 

In case that could still cause a deadlock, you've mentioned attributes, how should I tackle the problem with it?

Also if you can, please check the error I'm getting, as I'm not sure what I'm doing incorrectly.

BR, Domen

petek, 23. januar 2026 ob 17:06:49 UTC+1 je oseba armir....@itsyscom.com napisala:

Armir Veliaj

unread,
Jan 27, 2026, 11:32:30 AM (6 days ago) Jan 27
to CGRateS
Hi Domen,

In case you only have those scenarios, it should be fine and you can use shared groups as well, just not via APIs. For now, the only correct way to set shared groups is by loading accounts with balances containing shared groups through CSV files, as shown in this tutorial:
https://github.com/cgrates/cgrates/blob/master/data/tariffplans/oldtutorial/Actions.csv#L6

As a sample of  SharedGroups.csv you can check as below in order to apply different sorting logic of shared balances on each account.

SharedGroups.csv

#Id,Account,Strategy,RatingSubject
SHARED_A,cgrates.org:TEST_ACCOUNT1,*highest,
SHARED_A,cgrates.org:TEST_ACCOUNT1,*highest,


At the same time, you can also implement your scenario using Attributes and still use APIs, as in here:

{
  "method": "APIerSv2.SetAttributeProfile",
  "params": [
    {
      "Tenant": "cgrates.org",
      "ID": "ATTR_REDIRECT_ACC",
      "FilterIDs": [
        "*prefix:~*req.Account:TEST_ACCOUNT"
      ],
      "Attributes": [
        {
          "Path": "*req.Account",
          "Type": "*constant",
          "Value": "GROUP_ACCOUNT"
        }
      ],
      "Weight": 20
    }
  ],
  "id": 6
}


Please note that you may need to add "prefix_indexed_fields": ["*req.Account"] in the attributes section of cgrates.json if you follow the template API sample I provided.

Thanks,
Armir
Reply all
Reply to author
Forward
0 new messages