Sliding Windows for Periodic Balances and Meters
A sliding window determines a finite number of intervals in a periodic balance or meter, each of which is available for the same specified length of time.
- It defines the number of intervals to save in the subscriber's wallet for the associated periodic item. For example, if a daily periodic balance has a sliding window size of five, five daily intervals are created and saved in the wallet. Each interval is valid for events that have a timestamp that falls within that interval's start and end dates.
- It defines how many future and expired intervals to keep in the subscriber's wallet.
- It defines when new intervals are to be created and expired intervals removed.
You define the number of intervals to create in a sliding window when you create a periodic balance or meter. During usage, the window will contain a current interval, several expired intervals, and a number of future intervals. Expired and future intervals exist within the window to handle cases where rating of old events is required, and to ensure that if a session crosses from one interval to the next, it is properly rated with the corresponding intervals. For example, in the case where a product offer provides a 10 MB per-day allowance, the subscriber would have a periodic daily balance with 10 MB available for use. If the subscriber starts a data session at 11:55 PM that lasts 10 minutes and consumes 1 MB per minute, the 5 MBs used between 11:55 PM and 12:00 AM are charged against the previous day's interval and the last 5 MBs are charged against the current day's interval. This ensures that the previous day's balance can be charged properly based on when the MBs were consumed, even though the balance is not impacted until the session ends on the following day.
- The low-water mark value defines the minimum number of future periods, beyond the period used for the event being processed, that must be
available in the window. The value must be high enough to cover all future periods that an event might span when the event is rated. For example, a monthly periodic balance for
phone service should have a low-water mark value of at least 1 to guarantee that the window contains the current monthly period and the next monthly period, in case a call crosses
the month boundary.
When usage occurs, the low-water mark is examined and, if there are not at least this number of future periods available, the window is moved forward to make the total future periods available match the high-water mark value.
- The high-water mark value defines the maximum number of future periods that must be contained in the sliding window. This value is examined
when the low-water mark is triggered and determines how many future periods must be added to reach the high-water mark.
The high-water mark must be greater than or equal to the low-water mark and less than the window size. It should be large enough to minimize the frequency of the sliding but small enough to maximize how long expired balances are kept. A high value slides the window less often, which requires less processing, but also minimizes how long expired balances are kept. A low value requires more frequent slides but keeps expired balances longer. Expired balances are kept for situations in which events are received after the period they are associated with. This might occur when rating of old events is required or when offline rating is performed.
- Window size — five intervals
- Low-water mark — two future intervals
- High-water mark — two future intervals
Determining the Window Size
- The length of the periodic balance
or meter — daily, weekly, monthly, or yearly.
Smaller intervals might require more intervals to ensure enough expired intervals are maintained for rating of old events and future intervals are maintained for usage that spans multiple intervals.
- The number of expired intervals to
keep. After each slide operation is triggered, the maximum number of expired intervals in the window equals the window size, minus the high-water mark, minus one.
expired intervals = (window size - high-water mark) - 1
Note: For rollover balances, the number of expired intervals in the sliding window for periodic balances must be greater than the number of intervals a balance can be rolled over by at least one interval. For more information about rollover balances, see the discussion about balance rollovers. - The service type.
Typically, if the service does not provide subscribers with session-based usage, such as with SMS service, the window can be smaller because a single event will always occur completely in one interval. The main concern is with how many expired intervals to keep.
- Both the low-water mark and the high-water mark must be less than the window size. It cannot be equal to the window size because one interval is needed for the current interval.
- The low-water mark must be less than or equal to the high-water mark.
Determining the High-Water and Low-Water Mark Values
The high and low-water mark values are dependent on several factors that are vendor-specific.
- If the periodic balance or meter is updated by any usage that covers a span of time, such as voice service, the low-water mark must be high enough for the number of intervals that a single usage event could fall within. If N is the number of such intervals, then the low-water mark should be N-one. A low-water mark of zero means no future intervals; one means one future interval, and so on. Most usage measured in duration typically falls within two intervals, for example the current month and the next month, in which case the low-water mark can be one.
- If the periodic balance or meter is updated by usage that occurs at a specific moment in time, such as SMS, the low-water mark can be set to zero.
- Set the window size and high-water mark according to the amount of pricing history your company needs to keep. The highest possible value for the high-water mark is equal to the window size minus the low-water mark. At this setting, all history is lost when the window slides. The lower the value of the high-water mark, the longer the history is kept, but the window needs to slide more frequently. A high-water mark value of zero slides the window only as far as needed to maintain the low-water mark. This setting maintains the longest history for the balance or meter. For weekly, monthly, or yearly intervals, setting the high-water mark to zero is probably fine. For daily intervals, set the high-water mark to a value greater than zero.