0
0
Firebasecloud~20 mins

Server timestamps in Firebase - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Server Timestamp Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
2:00remaining
Understanding Firebase Server Timestamps Behavior

When you set a field in a Firestore document to firebase.firestore.FieldValue.serverTimestamp(), what will be the value of that field immediately after the write operation completes on the client?

AThe exact server time at the moment the write was processed by Firestore.
BA placeholder value that will be replaced asynchronously with the server timestamp once confirmed.
CThe client's local time at the moment the write was initiated.
DNull, because the server timestamp is not available on the client.
Attempts:
2 left
💡 Hint

Think about how Firestore handles latency and synchronization between client and server.

Configuration
intermediate
2:00remaining
Using Server Timestamps in Firestore Document Updates

You want to update a Firestore document's lastModified field to the current server time. Which of the following update commands correctly sets the lastModified field to the server timestamp?

Firebase
const docRef = firestore.collection('users').doc('user123');

// Which update command is correct?
AdocRef.update({ lastModified: firebase.firestore.FieldValue.serverTimestamp() });
BdocRef.update({ lastModified: new Date() });
CdocRef.set({ lastModified: firebase.firestore.FieldValue.serverTimestamp() });
DdocRef.update({ lastModified: firebase.firestore.Timestamp.now() });
Attempts:
2 left
💡 Hint

Consider which method updates only the specified fields and which value represents the server timestamp.

Architecture
advanced
2:30remaining
Designing a Firestore Schema with Server Timestamps for Audit Logs

You are designing an audit log system in Firestore that records user actions with timestamps. You want to ensure timestamps are consistent and trustworthy. Which architecture choice best achieves this?

AStore timestamps as strings formatted on the client side for readability.
BUse client-generated timestamps with <code>new Date()</code> and trust client clocks.
CUse <code>firebase.firestore.FieldValue.serverTimestamp()</code> for all timestamp fields to ensure server time consistency.
DUse a Cloud Function to add timestamps after writes, ignoring client timestamps.
Attempts:
2 left
💡 Hint

Think about trustworthiness and consistency of timestamps in distributed systems.

security
advanced
2:30remaining
Securing Firestore Writes with Server Timestamps

You want to prevent clients from spoofing timestamps in Firestore writes. Which Firestore security rule best enforces that the createdAt field is set only to the server timestamp?

Aallow write: if request.resource.data.createdAt == request.time;
Ballow write: if request.resource.data.createdAt == request.resource.data.createdAt;
Callow write: if request.resource.data.createdAt == request.auth.token.timestamp;
Dallow write: if request.resource.data.createdAt != null;
Attempts:
2 left
💡 Hint

Consider how Firestore security rules access server time and request data.

Best Practice
expert
3:00remaining
Handling Missing Server Timestamps in Offline Firestore Clients

When a Firestore client is offline and writes a document with a serverTimestamp() field, what is the best practice to handle the timestamp field in your app UI before the client reconnects?

ASet the timestamp field to null and never update it.
BShow the client's local time as the timestamp immediately after the write.
CHide the timestamp field completely until the client reconnects.
DDisplay a loading indicator or placeholder until the server timestamp is available.
Attempts:
2 left
💡 Hint

Think about user experience and data consistency when server data is delayed.