Skip to main content
hkh
Gold ⭐️
Nov 4, 2026 8:48 PM UTC
Solved

NiFi 2.12 – How to avoid a repeated DB lookup for every file

Hi all,

I'm looking for the recommended way to avoid making the same database call for every file in NiFi.

Environment

- Apache NiFi version: 2.12.0

- Deployment: [single node / cluster with X nodes]

Use case

Our filenames include a suffix, for example: SampleFileName_SampleSuffix.xml

For each file picked up by NiFi, we:

1. Read the suffix from the filename (SampleSuffix in the example above).

2. Look up that suffix in a database config table.

3. Use the result to decide where the file goes, for example move it to location XYZ or location ABC.

Problem

This DB lookup runs for every file. We process a large number of files, and many of them share the same suffix, so we keep making the same DB call and getting the same result.

 

Thanks in advance.

vafs
vafsAnswer
Gold ⭐️⭐️⭐️
Nov 5, 2026 4:18 PM UTC

Hello ​@hkh, 

Thanks for being part of our community. 

I think this could be a really use case for a Cache. 
This is a quick idea that may help you. 

  • Create a Secondary Flow to generate the cache: 
    QueryDatabaseTable → SplitRecord → ConvertRecord → PutDistributedMapCache
    You can schedule this to run every X minutes, so you have a fresh cache. 
  • Update the Primary Flow to read from that cache, not from the DB: 
    UpdateAttribute or the processor you have to extract the suffix → FetchDistributedMapCache pointing to cache. 
    Also include a failover plan, for not-found entries, so it looks the DB in that case. 

 

Here is an idea of the flows, take a look and test in your side to see if it works as you need. 

 

 

Regards,
Andrés Fallas
-- Was your question answered?
Please take some time to click on "Accept as Solution" below this post.
If you find a reply useful, say thanks by clicking on the thumbs-up button.

2 replies

vafs
Gold ⭐️⭐️⭐️
vafsAnswer
Gold ⭐️⭐️⭐️
Nov 5, 2026 4:18 PM UTC

Hello ​@hkh, 

Thanks for being part of our community. 

I think this could be a really use case for a Cache. 
This is a quick idea that may help you. 

  • Create a Secondary Flow to generate the cache: 
    QueryDatabaseTable → SplitRecord → ConvertRecord → PutDistributedMapCache
    You can schedule this to run every X minutes, so you have a fresh cache. 
  • Update the Primary Flow to read from that cache, not from the DB: 
    UpdateAttribute or the processor you have to extract the suffix → FetchDistributedMapCache pointing to cache. 
    Also include a failover plan, for not-found entries, so it looks the DB in that case. 

 

Here is an idea of the flows, take a look and test in your side to see if it works as you need. 

 

 

Regards,
Andrés Fallas
-- Was your question answered?
Please take some time to click on "Accept as Solution" below this post.
If you find a reply useful, say thanks by clicking on the thumbs-up button.

Translate
hkh
hkhAuthor
Gold ⭐️
Nov 6, 2026 7:30 PM UTC

Thank you so much for sharing the solution for the query. 

Translate