Billing in Cloud Computing - How it is done in StratosLive

Archived Content
This article is provided for historical perspective only, and may not reflect current conditions. Please refer to relevant product page for more up-to-date product information and resources.
  • By Amila Maharachchi
  • 1 Sep, 2011

Introduction

When hosting a public cloud, it is necessary to bill the users for consuming the cloud resources. It is how you get to earn money for offering the cloud. It is very important to bill the user for the correct usage, not less, nor more. If your values are wrong, users will loose their trust on your cloud deployment. On the other hand, users should be billed without any losses to the hosting party. Billing system has to be flexible too. Otherwise it will be difficult to match it with the business decisions. WSO2 StratosLive, the 100% open source, complete PaaS, comes with its own billing system to bill the tenants for using the cloud. Let’s have a look at the bill generation process of StratosLive.

Applies To

StratosLive 1.5.1

Content

Bill generation process

Shown below is a simple diagram to explain the base entities involved in bill generation.

Abstract view of billing system

There can be multiple billing engines in your environment. In StratosLive, there are two of them. One is for scheduled bill generation (monthly invoice) and the other is for on-demand bill generation (interim invoice). Both these engines use a single billing database. Each of these engines have a set of handlers to be executed. These handlers can be configured via the billing-config.xml. They are executed by the engine at the time of bill generation. Shown below is a segment from the billing-config.xml

<task id="multitenancyScheduledTask">
 
  <handlers>
 
     <handler service="org.wso2.carbon.billing.mgt.handlers.MultitenancySubscriptionFeedingHandler">
 
     </handler>
 
     <handler class="org.wso2.carbon.billing.core.handlers.SubscriptionTreeBuildingHandler">
 
     </handler>
 
     <handler class="org.wso2.carbon.billing.core.handlers.RuleHandler">
 
         <parameter name="file">multitenancy-billing-rules.drl</parameter>
 
     </handler>
 
     <handler class="org.wso2.carbon.billing.core.handlers.InvoiceCalculationHandler">
 
     </handler>
 
     <handler class="org.wso2.carbon.billing.core.handlers.DefaultFinalizingHandler">
 
     </handler>
 
     <handler class="org.wso2.carbon.billing.core.handlers.EmailSendingHandler">
 
         <parameter name="file">email-billing-notifications.xml</parameter>
 
     </handler>
 
  </handlers>
 
</task>

Data used in bill generation

  • Subscription details – subscriptions of the user for the duration considered in the bill generation. There is a subscription entry for each usage plan which the user was subscribed to during the billing period
  • Usage details – Usage details of the user for the month of bill generation. This includes bandwidth usage (webapp bandwidth, service bandwidth and registry bandwidth) and registry storage of the user.
  • Pricing strategy – This defines how users are going to be charged for subscription and overusage. Shown below is a sample xml file which defines the pricing strategy.
<package name="Demo">
 
  <subscriptioncharge>10</subscriptioncharge> <!-- $ per month -->
 
  <users>
 
     <limit>10</limit>
 
     <charge>0</charge> <!-- charge per additional user -->
 
  </users>
 
  <resourcevolume>
 
     <limit>25</limit> <!--MB per user -->
 
     <overusecharge>0.1</overusecharge>
 
  </resourcevolume>
 
  <bandwidth>
 
     <limit>2000</limit> <!-- MB per user -->
 
     <overusecharge>0.1</overusecharge> <!-- $ per additional MB -->
 
  </bandwidth>
 
</package>

When does bill generation happen?

As I mentioned previously, monthly invoice is generated by a scheduled task. This is achieved via Synapse scheduled tasks. When the billing manager is started (i.e. when the server starts), a bill generation task is scheduled for the billing engine. This task-scheduling can be configured via the billing-config.xml.

Let’s go through the bill generation step-by-step. Billing engine for scheduled bill generation executes the following set of handlers.

1.SubscriptionFeedingHandler – Retrieves the subscription entries relevant to the bill generation period. For each subscription, relevant user's usage data is also retrieved. Subscription entries are added to the BillingEngineContext to be used by other handlers.

2.SubscriptionTreeBuildingHandler – Goes through all the subscription in the context and arranges the subscriptions of the same customer together. Creates invoices and assigns the subscriptions to them. Fills some data of the invoice such as invoice dates, payments falling under the billing period.

3.RuleHandler – Rules are used to calculate the subscription fees. Rule handler executes the rules over the billing engine context. This will assign a subscription fee for all the subscriptions in the context.

4.InvoiceCalculationHandler – Over usage charges are calculated by this handler according to the pricing strategy defined in an xml file. Total cost, total payments and carried forward values are also calculated. At this moment, there is a complete invoice for all the customers in memory.

5.Finalizing Handler – This handler takes care of storing the invoices in the billing database.

6.EmailSendingHandler - After generating and storing the invoices, customers have to be notified. It is done by the email sending handler. When this is done, you receive an email notifying you about the invoice.

The diagram below gives an idea on what happens in the first four handlers.

What happens when the handlers are executed

Scheduled vs. on-demand bill generation

These two operations are carried out by two billing engines.

Scheduled generation executes two additional handlers than the on-demand generation. They are the finalizing handler and the email sending handler. When the invoice is generated on-demand, it is not stored in the database (because it is only for presenting to the user). No email notification is necessary because the invoice is shown in the UI. That is the reason for FinalizingHandler and EmailSendingHandler not needing in on-demand bill generation.

Flexibility

The whole bill generation process is the execution of a set of handlers. If you want to add something new to the flow, you can simply write a handler and mention that handler in the billing-config.xml for it to be executed by the engine.

Billing component can be further improved to calculate all the costs via rules, making it easier to change cost items and pricing because all you need is to edit the rule file. This avoids any code-level change when it comes to changes in calculating the cost, which is a huge advantage.

Now that we have got an understanding of how billing happens in StratosLive, let us investigate some key components of the StratosLive invoices.

StratosLive invoice - What does it contain?

Shown below is a sample invoice and I'll describe what it includes. You can view the invoice in StratosLive Manager's Home → Billing & Metering → Past Invoices.

Sample invoice

Following information is available in the invoice.

A) Invoice number

B) Invoice period (i.e. for which time period does this invoice applicable) and Invoice date – date which the invoice was generated

C) Subscription fees for the subscriptions you have used during the period. For example, if you have used to the same subscription there will be one entry for this. But in this sample invoice, the user has used a SMB usage plan for 5 days and changed to a Demo usage plan. Therefore, there are two entries in the subscription fee section. It is important to notice that the subscription fee is calculated only for the number of days which you were subscribed to it.

D) Over-usage charges – At the time of bill generation, usage data is retrieved by the billing engine and compared with the allowed usage limits for the active subscription at that time. If the user has exceeded the allowed limit, excess usage is charged. Charging the excess usage depends on the desire of the cloud owner. For example, in the above invoice, the tenant has consumed 32MB of excess storage. But it is not being charged. Overuse charges are calculated for Bandwidth and Storage. The invoice clearly mentions how much is charged for each of them.

E) Payment details within the period – If you did a payment for your previous invoice, it should clearly be mentioned in this invoice. You can see it in the sample invoice too.

F) Finally, there is a summary which includes the Brought Forward value, Total cost for this period, Total payments during this period and the Carried forward value.

G) After these details, you get the PayPal button to pay the invoice securely.

Interim Invoice

You will not find this facility in many billing systems. But StratosLive provides you a view of your costs for usage up to a particular moment. Interim invoice shows your costs from the last invoice date to this moment. Many cloud services only provide you the monthly invoice at the end of the month. But we provide you the invoice on demand.

Further, if you have been charged for over using resources, you can check whether the excess usage amounts mentioned in the invoice are accurate by going through you usage report for the month. Usage report can be found at Home →Billing & Metering →Usage Report

To summarize the content, this article describes how and when bill generation happens in StratosLive and it also explains generated invoice.

Author

Amila Maharachchi, Senior Software Engineer, WSO2 Inc.

About Author

  • Amila Maharachchi
  • Associate Director / Architect
  • WSO2