Giter VIP home page Giter VIP logo

a1pubsub's Introduction

a1pubsub's People

Contributors

james007crocker avatar kira-sh avatar naqi-tt avatar renovate-bot avatar supermacro avatar

Watchers

 avatar  avatar

a1pubsub's Issues

Not serializing failed validation data correctly.

Seeing logs like this in our logs:

[pubSubMessageHandler] - 0322fba9-4609-43b4-8e8e-38e9f4fe0352 - Failed to process pubsub request - {"error":"invalid_event_data","reason":"Data for subscription \"<REDACTED>\" did not pass validation. Data: [object Object]"}

The issue is here:

reason: `Data for subscription "${subscription}" did not pass validation. Data: ${untypedJsonData}`,

We're not calling JSON.stringify

No lock acquired when running on a multi-instance setup

Imagine the following architecture:

Screen Shot 2020-06-16 at 11 44 49 AM

In this (very common) architecture, there is a scenario that is very common with PubSub Push Messages.

  • Some system publishes a message
  • GCP receives message and then pushes message to a subscriber
    • Let's suppose message has id 123
    • subscriber has the above architecture
  • Load balancer receives message 123 and forwards to node A
  • a1pubsub is currently processing message 123
  • Google sends a duplicate message
    • recall that google does not guarantee exactly once delivery of messages ... if it did, then you wouldn't need a1pubsub :)
  • Load balancer receives message 123 a 2nd time, but forwards it to node B
  • a1pubsub is currently processing message 123

Oh nooo, node B was not aware that node A was already processing message 123.

Thankfully the fix is quite straight forward. And provides a reasonably high level of confidence. Assumption is that query_latency < latency_between_original_and_duplicate_pubsub_message. If this assumption is not true, then this fix doesn't work.

You can acquire a lock on messages by leveraging the EventStatus enum.

https://github.com/supermacro/a1pubsub/blob/master/src/index.ts#L42

And then inside of handlePubSubMessage, check if there's already a cached message that is in_progress. If true, then throw away the current message since it's a duplicate.

CLI

Would be great to have a CLI to make working with pubsub even easier:

  • Create Topic
  • Create Subscription
    • enforce the <eventName>__<actionToTake> naming pattern
    • generate ngrok link automatically for local development
    • set up authentication automatically

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.