0
0
Firebasecloud~20 mins

Distributed counters pattern in Firebase - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Distributed Counters Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Architecture
intermediate
1:30remaining
Why use distributed counters in Firebase?

In Firebase, what is the main reason to use distributed counters instead of a single document counter?

ATo prevent any writes from failing by locking the counter document.
BTo avoid contention and improve write scalability by splitting increments across multiple documents.
CTo reduce the total number of reads by storing all counts in one document.
DTo ensure the counter value is always exactly consistent in real-time without delay.
Attempts:
2 left
💡 Hint

Think about what happens when many users try to update the same counter at once.

service_behavior
intermediate
1:30remaining
Behavior of incrementing a distributed counter shard

Given a distributed counter with 5 shards, what happens when you increment one shard document in Firebase?

AThe increment fails if the shard document does not exist.
BAll shard documents increase their count by one simultaneously.
CThe total count document is updated directly without changing shards.
DOnly the shard document's count increases by one; the total count is the sum of all shards.
Attempts:
2 left
💡 Hint

Consider how distributed counters store counts across shards.

security
advanced
2:00remaining
Securing distributed counter shards in Firebase

Which Firebase security rule best prevents unauthorized users from arbitrarily modifying distributed counter shard values?

AAllow writes only if the increment value is exactly 1 and the user is authenticated.
BAllow any write to shard documents without restrictions.
CAllow writes only if the user is an admin, ignoring increment values.
DDeny all writes to shard documents.
Attempts:
2 left
💡 Hint

Think about limiting increments to small controlled changes by trusted users.

Configuration
advanced
2:00remaining
Configuring shard count for a distributed counter

You want to configure a distributed counter in Firebase to handle up to 1000 increments per second without contention. Which shard count is most appropriate?

A100 shards to reduce contention while controlling cost.
B10 shards to balance between performance and cost.
C1 shard because it simplifies the design.
D1000 shards to allow one increment per shard per second.
Attempts:
2 left
💡 Hint

More shards reduce contention but increase cost and complexity.

🧠 Conceptual
expert
1:30remaining
Calculating total count from distributed counter shards

You have a distributed counter with 4 shards having counts: 12, 15, 10, and 13. What is the total count returned when you read the counter?

A40
B12
C50
D15
Attempts:
2 left
💡 Hint

Sum all shard counts to get the total.