Giter Club home page Giter Club logo

farcaster-indexer's Introduction

Farcaster Indexer

This is an indexer that listens for messages from a Farcaster Hub and inserts relevant data into a postgres database.

The most performant way to run this is to co-locate everything (hub, node app, postgres, redis) on the same machine. I recommend Latitude (referral code for $200 of free credits).

How to run

Clone this repo

git clone -b hubs https://github.com/gskril/farcaster-indexer.git

Install dependencies

yarn install

Create a .env file with your hub, database, and redis connection details

cp .env.example .env

Run the latest database migrations

yarn kysely:migrate

Run the indexer

# Recommended to get the full state. You only need to run this once.
# Streaming will start after the backfill is complete.
yarn run backfill

# Ignores backfill and start streaming from the latest recorded event.
# You should run this after one initial backfill.
yarn start

How it works

  • Backfill and streaming are separate processes.
  • Every operation is run through BullMQ for better concurrency and error handling.
  • For backfill, the indexer adds all FIDs (in batches of 100) to a queue and processes them in parallel. The WORKER_CONCURRENCY environment variable controls how many workers are spawned.
  • Once backfill is complete, the indexer subscribes to a hub's event stream and processes messages as they arrive. BullMQ is used as middleware to ensure that hub events are getting handled fast enough, otherwise the stream will disconnect.

Extras

If you want to add search functionality, you can manually apply the SQL migration at src/db/search-migrations.sql

farcaster-indexer's People

Contributors

alexpaden avatar davidfurlong avatar dependabot[bot] avatar gskril avatar psatyajeet avatar zachterrell57 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

farcaster-indexer's Issues

Speed up searchcaster full text search

My plan is now to:

Return all grandchildren and ancestors per cast fetch

Currently, if devs fetch a cast from Searchcaster, it returns children with depth 1. Would it be desirable if it returns all the grandkids per fetch? HN and Reddit does this - when users view a post, all the comments of that post gets displayed. The API looks like this: https://hn.algolia.com/api/v1/items/33757484 (notice that the "children" key recursively contains all the replies). Plus, it would be extra nice if it also returns all the ancestors (all the casts from the root thread to the fetched cast, if there's any).

I'm down to help to make this happen.

Workers are dropping messages during backfill

Backfill with >1 concurrency will seemingly just miss all the links (or some other data type) for a fid(s) but get all casts, reactions, etc from that user.

The user(s) and data type(s) it skips are inconsistent and there are no errors in the logs. It's as if only part of the getFullProfileFromHub() function is running, or Postgres is somehow missing requests.

Verified by running a backfill with WORKER_CONCURRENCY=5, then running it again with WORKER_CONCURRENCY=1 and seeing that some tables had rows with newer updated_at values even though the message timestamp was old.

Thanks to @stephancill for finding the bug by comparing the number of rows in different tables after backfills with different concurrency values.

image

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.