Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backend: remove postgres, use redis for api/ledgers data #209

Merged
merged 15 commits into from
Jan 14, 2022
Merged

Conversation

acharb
Copy link
Contributor

@acharb acharb commented Jan 12, 2022

WHAT
remove use of postgres on the backend, and use redis for the api/ledgers/public data

WHY
The dashboard api endpoints essentially cache organized data given from Horizon, which is more of a use case for redis than postgres. And since postgres was just being used for a single purpose (storing all ledgers), we can now remove it and have a single storage option on the backend, reducing the complexity of the backend. In order to do this the data is now organized before being stored in the cache, as opposed to after like it was with postgres.

closes #198
part of the backend refactor plan

@stellar-jenkins
Copy link

Preview deployed to development environment: https://dashboard.prototypes.kube001.services.stellar-ops.com

@stellar-jenkins
Copy link

Preview deployed to development environment: https://dashboard.prototypes.kube001.services.stellar-ops.com

@stellar-jenkins
Copy link

Preview deployed to development environment: https://dashboard.prototypes.kube001.services.stellar-ops.com

@stellar-jenkins
Copy link

Preview deployed to development environment: https://dashboard.prototypes.kube001.services.stellar-ops.com

@stellar-jenkins
Copy link

Preview deployed to development environment: https://dashboard.prototypes.kube001.services.stellar-ops.com

@stellar-jenkins
Copy link

Preview deployed to development environment: https://dashboard.prototypes.kube001.services.stellar-ops.com

@stellar-jenkins
Copy link

Preview deployed to development environment: https://dashboard.prototypes.kube001.services.stellar-ops.com

@stellar-jenkins
Copy link

Preview deployed to development environment: https://dashboard.prototypes.kube001.services.stellar-ops.com

@acharb acharb changed the title (wip) - remove postgres, use redis for api/ledgers data backend: remove postgres, use redis for api/ledgers data Jan 13, 2022
@acharb acharb marked this pull request as ready for review January 13, 2022 17:49
Copy link
Member

@leighmcculloch leighmcculloch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few questions (❔❓), I think driven by just lack of knowledge on my part on how this works. These questions don't need to block anything, except maybe the question (❓) on how ledger data is being added together, I didn't expect that.

backend/ledgers.ts Show resolved Hide resolved
backend/ledgers.ts Outdated Show resolved Hide resolved
Comment on lines 100 to 107
cachedLedgers.splice(index, 1, {
date: date,
transaction_count:
cachedLedgers[index].transaction_count +
ledger.successful_transaction_count +
ledger.failed_transaction_count,
operation_count:
cachedLedgers[index].operation_count + ledger.operation_count,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ Why do we add to a ledger we already have? I would have expected once we know about a ledger's data that we wouldn't mutate it after then because the ledger shouldn't change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe the naming should be changed. The cache is stored like so:

[
  {
    "date": "01-13",
    "transaction_count": 5245946,
    "operation_count": 10088417
  },
  {
    "date": "01-12",
    "transaction_count": 5787617,
    "operation_count": 11333624
  },
...

which is what cachedLedgers is referring to and is what's being updated. Which technically isn't a ledger, I couldn't think of a better word 🤔 . This code no longer stores every LedgerRecord from horizon like it did before with postgres.

I think maybe this would be clearer when LedgerRecord is not any anymore

// TODO - use any until https://github.com/stellar/js-stellar-sdk/issues/731 resolved
export type LedgerRecord = any;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LedgerStat? this was referring to something else with postgres before I removed it, but I think could be fitting here. LedgerAggregate might be better, but a mouth full. Thoughts on either of those?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like LedgerStat the more I think of it: e6fb860

if you disagree lmk though

Copy link
Contributor

@quietbits quietbits left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My comments are more like eslint stuff. 😊 I'm not familiar with redis or postgress, so I would rely on a backend dev to check that.

backend/app.ts Show resolved Hide resolved
backend/ledgers.ts Outdated Show resolved Hide resolved
backend/ledgers.ts Outdated Show resolved Hide resolved
backend/ledgers.ts Outdated Show resolved Hide resolved
backend/ledgers.ts Outdated Show resolved Hide resolved
backend/ledgers.ts Outdated Show resolved Hide resolved
backend/ledgers.ts Outdated Show resolved Hide resolved
test/tests/unit/backend.ts Outdated Show resolved Hide resolved
test/tests/unit/backend.ts Outdated Show resolved Hide resolved
@stellar-jenkins
Copy link

Preview deployed to development environment: https://dashboard.prototypes.kube001.services.stellar-ops.com

@stellar-jenkins
Copy link

Preview deployed to development environment: https://dashboard.prototypes.kube001.services.stellar-ops.com

@stellar-jenkins
Copy link

Preview deployed to development environment: https://dashboard.prototypes.kube001.services.stellar-ops.com

1 similar comment
@stellar-jenkins
Copy link

Preview deployed to development environment: https://dashboard.prototypes.kube001.services.stellar-ops.com

@stellar-jenkins
Copy link

Preview deployed to development environment: https://dashboard.prototypes.kube001.services.stellar-ops.com

@stellar-jenkins
Copy link

Preview deployed to development environment: https://dashboard.prototypes.kube001.services.stellar-ops.com

1 similar comment
@stellar-jenkins
Copy link

Preview deployed to development environment: https://dashboard.prototypes.kube001.services.stellar-ops.com

@acharb acharb merged commit b2f0676 into master Jan 14, 2022
@acharb acharb deleted the acharb-no-pg1 branch January 14, 2022 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use Redis for caching
4 participants