Your company has developed a message board system that is being used by hundreds of web sites. The licensing model gives away the software for free but produces recurring revenue by charging ten cents per unique user that posts on the board. You have been tasked with developing a billing system that can determine in real-time the accounts-receivable per customer for all customers. Explain how your system works and why it’s a good solution for providing real-time information

Dani AI

Generated

raised a real-time billing problem (per-unique-poster charging); moderators and closed the thread as homework, but the following concise, practical design is useful for real deployments.

Design summary: treat each post as an event (customer_id, user_id, post_id, timestamp) and process it via a durable stream (Kafka/Rabbit/Kinesis). Maintain a fast, in-memory "seen users" set per customer+billing-period for real-time answers and a durable relational store for auditability. On arrival, atomically test-and-add the user to the in-memory set; if the add is new, increment that customer's AR counter and persist the new unique user into the database (using a unique composite key to make the DB idempotent). Keep the raw event log so you can replay and reconcile the fast store against the authoritative DB.

Example pseudocode:

onPostEvent(e):
  key = "seen:" + e.customer_id + ":" + period
  if redis.SADD(key, e.user_id) == 1:
    redis.INCRBYFLOAT("ar:" + e.customer_id + ":" + period, price)
    db.insert_ignore("billed_users", {customer_id, user_id, period, first_seen})

Notes and cautions: use atomic operations or a short Lua script in Redis to avoid race conditions. For billing you normally need exact counts and an auditable trail—probabilistic structures like HyperLogLog trade accuracy for memory and are not recommended where exact invoicing or legal records are required. Add a nightly reconciliation job that compares the durable DB totals to the real-time counters and corrects discrepancies. Watch for duplicate events, clock skew, and partition rebalances in the stream processor; make every operation idempotent.

Recommended Answers

All 2 Replies

This reeks of homework, and it would be better placed in the Software Design forum.

Again, I have to agree. Closing this thread.

This is strike 2. If I find one more post from you asking flat out for us to do your homework for you, I'll have to unsheath THE BANBLADE!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.