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.

When a subscriber purchases a product offer that uses a periodic balance or a periodic meter, a sliding window is created for it. The sliding window serves several purposes:
  • 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 number of expired intervals and future intervals are controlled by configuring two markers that determine when and how far to slide the window: a low-water mark and a high-water mark.
  • 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.

For example, a monthly periodic balance has the following sliding window attributes.
  • Window size — five intervals
  • Low-water mark — two future intervals
  • High-water mark — two future intervals
In January, a subscriber purchases a streaming media service that provides 5 GB per month. Upon purchase, a sliding window of five intervals is added to the subscriber's wallet: January, February, March, April, and May. The periodic balance has one current interval and four future balance intervals, as shown in Figure 1.
Figure 1. Sliding Window with Five Intervals
Sliding Window with Five Intervals
If the subscriber next uses the service in March, making the March interval the current interval, MATRIXX Engine examines the low-water mark and determines two future intervals in the window. Because the low-water mark is 2, it does not slide the window before rating the event. The window also has two expired intervals, which are depicted as being crossed out in Figure 2.
Figure 2. Sliding Window with a Valid Low-Water Mark
Sliding Window with a Valid Low-Water Mark
If the subscriber next uses the service in April, making the Apr interval the current interval, MATRIXX Engine examines the low-water mark and determines only one future interval in the window. This does not satisfy the low-water mark value of two future intervals, as shown in Figure 3.
Figure 3. Sliding Window with an Invalid Low-Water Mark
Interval Balances with a 3-Balance Sliding Window
As a result, the window is triggered to slide. To determine how far it to slide it, MATRIXX Engine examines the high-water mark value (two future intervals) and slides the window forward to add one additional interval to the window (Jun). Figure 4 shows the sliding window, which has two future intervals after the slide operation to satisfy the high-water mark.
Figure 4. Sliding Window with a High-Water Mark
periodic Balances with a 3-Balance Sliding Window
Notice that now only two expired intervals in the sliding window (Feb, Mar) because the sliding window size is five intervals and Jan no longer fits. All intervals that expired before the Feb interval are removed and recycled.
Note: The sliding window is managed differently for on demand periodic balances. Instead of checking for future intervals, MATRIXX Engine checks for how many available but unused intervals exist. If the number of unused intervals is below the low-water mark, the window slides. After the slide, the number of unused intervals is equal to the high-water mark.

Determining the Window Size

The size of the sliding window is dependent on several factors, including the following:
  • 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.

The following window behavior can be used to determine how large to make the window:
  • 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.