unit4
unit4
2
• Option 2: Keep sending them, but that risks data loss if the system can't
handle the load.
A good streaming API should let clients know they’re falling behind. Sadly,
many third-party APIs don’t do that. If you’re building your own API,
definitely include this feature.
Client-Side Considerations
As a developer, you should ask yourself:
1. Am I keeping up with the stream?
2. What happens if I don’t?
3. How can I scale my client to handle more data?
3
3.Explain different areas where data loss can occur.
4
• In the UI display
Even if the data is processed correctly, it might not show up in the user
interface due to rendering errors or browser issues.
5
To handle this, keep a record of processed messages, using a unique ID or
hash. This adds complexity and requires more storage, but helps avoid
duplicates—even if the system crashes.
6
5. Explain hybrid message logging with partial ACKing and
distributed storage for processed messages.
Figure : HML with partial ACKing and distributed storage for processed
messages
when one streaming server goes down and the client connects to another, it
might resend messages you’ve already processed. So, you need to always check
and skip duplicates using a distributed store.
But if the stream is very fast, checking a remote store every time can slow
things down. To avoid this, keep recent messages in a local cache and
occasionally sync with the distributed store—this keeps things quick and
reliable.
7
8
6. Explain the steps required for exactly-once processing for
Node.js with neat diagram.
9
6. Store event— Store the event as we did in step 3.
7. Send payment request— We’re now ready to send the
payment request to our payment processor.
8. Receive ACK— Wait for an “ACK” confirming the payment was
successful. If the payment processor doesn’t support ACKs, try
querying the system to confirm success. If that’s not possible,
use a more asynchronous approach or run a separate process to
verify the payment later.
9. Remove event— At this point we know that the payment
system has processed the request, so we can safely delete the
royalty event received in step 1 from our backing store.
10. Remove— This is a remove from the RocksDB. In this case,
it will remove the royalty event we received in step 1.
11. ACK event— After processing, send an ACK to the
streaming API to confirm the message is done. If the API
doesn’t support ACKs, use another way to signal completion.
Since ACKs might get lost, add a check before processing to
avoid handling the same message twice.
10
11