r/snowflake•
py_root

Realtime CSV data load to snowflake

Hi folks,

Does anyone worked here on loading CSV files to snowflake in near realtime basis.

I have a problem statement where I need to load data from CSV files to snowflake as soon as the file arrives in S3. Files are arriving in s3 every 30 seconds or in a minute.

What could be the best approach for this.

Any suggestions or helps are appreciated. thanks

Posted Mar 31, 2022, 3:33 PM UTC

415
dementeddrongo•
11
thrown_arrows•

I would like to add that using warehouse instead of snowpipe will cause warehouse to open whole time ( if rule that minimum run time for warehouse is 1 min is stil in use ). Snowpipe should costs only runtime in seconds resolution.

3
py_rootOP•

Yes you are correct and I am using snowpipe which runs every 15 min to check modified file of last 15 mins to upload. Now looking for S3 event notification setup using object key name filtering.

2
xeroskiller•

Snowpipe has a serverless option now. It bills as part of GS, meaning it only gets billed if you exceed 10% of that day's overall credit consumption. This can help with the dreaded 'never suspending task warehouse' issue.

2
thrown_arrows•

That is what i meant, someone from snowflake said that snowpipe usage is billed by second vs warehouse which is 1 minute everytime you start it, which leads easily into situation where you have warehouse open all the time.

2
xeroskiller•

100% correct. Happened to me, once. Left a task running every minute as a test, and forgot it. Came back to over 500 credits used up over the course of 4 days.

Make sure you set up Resource Monitors, hahaha

2
mr2711•

Snowpipe Serverless is billed per sec per core unlike Cloud Services where you are billed for usage over 10% of daily compute used.

https://docs.snowflake.com/en/user-guide/data-load-snowpipe-billing.html

1
xeroskiller•

You're right. I was definitely thinking of tasks. I even said 'task warehouse', haha

1
xeroskiller•

People say Snowpipe is the obvious suggestion, and they're mostly right. The problem with Auto-ingest snowpipe is that is complex, and requires multiple services and objects on both sides. Once set up, it's pretty consistent, and does its job admirably, but I'll take a chance and suggest a different route. Two, to be precise.

First, since this data is basically near-real-time, you could look at setting up a Kafka cluster. Confluence offers managed Kafka clusters, and they 'automate' the snowpipe stuff, file stuff, staging stuff, etc... This can be a bit of work, as well, and requires tweaking, in the long term. The gain, though, is you set up Kafka, point it at Snowflake, and you're mostly done.

Second, since you have a fairly expected cadence, you could look at running a task, which holds a copy command. The gain is in simplicity, as you have a single SQL statement/object which does all the work, and maintains whatever latency on data that you deem appropriate. It used to be that tasks would require a warehouse, and given that they would keep it running, would cost a minimum of 24 credits a day to keep running. Now, you can set up a serverless task, though you still end up paying more for it, long-term.

One thing to keep in mind is that file size has a dramatic impact on throughput, including undersized files. The case can often be made that collecting the files and batching them will save a ton of money, as you spend less time 'spinning up' and 'spinning down' clusters, and more time keeping them saturated. With that having been said, though, for a RAW area, this often doesn't matter, as you'll be effectively 're-clustering' the data, anyway.

Hope this helps. Feel free to ask additional questions. Good Luck!

5
py_rootOP•

Your response is quite insightful. Thanks for wishing me☺️

For first approach with Kafka I guess it requires a lot of efforts before it will get up and running like a well oiled machine.

Second approach, the size of file is approx 10MB or less. As of now I have created a snowpipe using copy command which reads CSV file data from S3 stage and copy it to the snowflake table. When I started working with snowflake I was not aware of the task scheduler feature available in it so used python script to run the snowpipe refresh every 15 minute. Now my team wants that data need to be loaded as soon as it arrives in S3. So started looking auto ingestion using sns it seems a bit complex but giving it a try to test it.

I am hoping auto ingestion should help otherwise we have to look for different options.

2
xeroskiller•
2
py_rootOP•

I will take a look at it. Thanks 👍

1
xeroskiller•

One more option to call out, assuming you have a way of 'knowing' when a file drops. Snowpipe supports a bunch of Rest API endpoints, one of which can execute the pipe.

That's what Kafka does, under the hood. It drops the file, and runs a pipe it created on setup to ingest.

1
alphatachyon•

Snowpipe auto ingest with sqs notifications on aws

1