zooniverse / classroom

Front end for the education-api (https://github.com/zooniverse/education-api/)
https://classroom.zooniverse.org/
Apache License 2.0
0 stars 1 forks source link

Carto cannot handle "large and complex" requests #191

Closed shaunanoordin closed 2 years ago

shaunanoordin commented 4 years ago

Functionality Issue / External Dependency Issue

Initial reports:

In WildCam Gorongosa Lab's map explorer, users cannot download the CSV results if too many filters are active. (See below)

NOTE: this problem would apply to any WildCam Lab that uses Carto, which mean Darién should also be affected.

Investigation

Testing Steps

Inspecting the network requests shows that the error is coming from the external map database provider, Carto. The error is as follows:

Request:
GET https://MY-URL.carto.com/api/v2/sql?format=CSV&q=MY-SQL-QUERY

Response:
429 Too Many Requests
body: {
  context: "limit"
  detail: "datasource"
  error: [
    "You are over platform's limits: SQL query timeout error. Refactor your query before running again or contact CARTO support for more details."
  ]
}

Analysis

To sum up the problem, our external map database provider is experiencing timeout issues when it processes "large and complex" database requests.

Workarounds

Users can still download the WHOLE dataset (i.e. no filters, just click Download) and then perform their own filtering on their spreadsheet programs. I think the term is "using pivot tables in Excel"?

Status

Major problem.

One potential solution, I think, is to flatten the database (instead of camera, subjects, and aggregations tables, just merge them into one flat table, to avoid runtime JOIN functions) but that has its own problems. 1. there's no guarantee that the flattened database will work any better (maybe it's not the multiple runtime JOINs that are complex to Carto but the AND clauses??) given the time required to set it up, and 2. the problem is still with Carto's 5 second timeout.

Another solution is to move away from Carto altogether. Hmm!

shaunanoordin commented 2 years ago

Carto has been replaced with a Zooniverse-hosted map database server. Woohoo!