Connect vs Import External Data
Complete the full lesson to earn 25 points
Work through each section, then tap “Mark as Complete” on the last one.
✦ Skip the page breaks and see fewer ads — read each lesson on a single page with Pro
Lesson: Connect vs. Import External Data
Introduction: The Architect’s Dilemma
When designing a data architecture, one of the most fundamental decisions you will face is how to bridge the gap between your application and external data sources. Whether you are building a dashboard, a reporting engine, or a complex analytical platform, you must decide whether to pull that data into your own ecosystem (Import) or leave it where it lives and access it on demand (Connect). This decision is rarely just a technical preference; it is a strategic choice that dictates the cost, latency, reliability, and security posture of your entire project.
Many engineers default to "importing" data because it feels safer. Having the data under your control means you don’t have to worry about the external source going down, and you can index it exactly how you want for fast queries. However, importing data brings significant overhead: you must handle data synchronization, storage costs, compliance with data residency laws, and the complex task of ensuring that your copy of the data remains accurate over time.
Conversely, "connecting" to data—often called "live querying" or "federated access"—keeps the source of truth in its original location. This approach minimizes storage requirements and guarantees that you are always looking at the most recent data. Yet, this path introduces its own set of challenges, such as dependency on the external system’s performance, potential latency issues during complex joins, and the risk of hitting API rate limits or security bottlenecks. In this lesson, we will dissect both strategies, provide a framework for choosing the right one, and look at how to implement them effectively.
Understanding the Import Strategy
The import strategy involves creating a physical copy of the external data and storing it within your own infrastructure. This is often the preferred route for high-performance applications where query speed is paramount and the data volume is manageable. When you import data, you are essentially creating an ETL (Extract, Transform, Load) pipeline. You extract the data from the source, transform it into a format that matches your database schema, and load it into your local storage.
Why Choose Import?
The primary driver for importing data is the need for deep, complex analysis that the source system cannot support. For example, if you need to perform a multi-way join between an external CRM database, an internal sales database, and a marketing spreadsheet, the source systems likely lack the compute power or the necessary data to perform those joins. By importing everything into a centralized data warehouse, you gain the freedom to run any query you want without impacting the performance of the source systems.
Furthermore, importing data provides a "buffer" against source system outages. If your application relies on a third-party API that experiences frequent downtime, an imported cache ensures that your users can continue to interact with the data they need, even if it is slightly stale. This is particularly useful for mobile applications or user-facing dashboards where a "500 Internal Server Error" is unacceptable.
The Lifecycle of an Imported Dataset
- Extraction: Fetching data from the source, usually via API calls, file transfers (SFTP/S3), or database replication streams.
- Staging: Landing the raw data in a temporary storage area where it can be validated for schema drift or corruption.
- Transformation: Cleaning, deduplicating, and normalizing the data to fit your internal domain model.
- Loading: Inserting the processed data into your primary application database or analytical store.
Callout: The "Staleness" Trade-off When you import data, you accept that your data is, by definition, historical. Even with a high-frequency sync, there is a gap between the moment an event happens in the source and the moment it appears in your system. You must define an acceptable "Freshness SLA" (Service Level Agreement) to determine how often you need to run your sync jobs.
Understanding the Connect Strategy
Connecting to data, or "Live Querying," means your application sends queries directly to the external source. Instead of moving the data to you, you move the logic to the data. This is becoming increasingly popular with the rise of modern cloud data warehouses and virtualization layers. When you run a query in your dashboard, the system translates your request into the native language of the source system (e.g., SQL for a database, or a specific REST API request for a service) and retrieves only the result set.
Why Choose Connect?
The most compelling reason to use a connection-based approach is data governance and security. In many industries, such as healthcare or finance, moving data across different storage environments is a compliance nightmare. By keeping the data at the source, you reduce the surface area for security breaches and ensure that access controls defined at the source are respected. If a user doesn't have permission to see a record in the source system, they won't see it in your application either.
Another benefit is the elimination of storage costs and synchronization complexity. You don't have to build and maintain pipelines, write error-handling logic for failed syncs, or worry about disk space. For low-frequency, high-value lookups, this is often the most cost-effective solution.
Technical Implementation of Connections
To connect to data, you typically use a "Data Virtualization" layer or a "Federated Query" engine. These tools act as a translator, allowing you to write a single query that pulls from multiple disparate sources simultaneously.
-- Example of a federated query using a virtualized view
-- This query joins a local table with an external BigQuery table
SELECT
local_users.name,
external_sales.total_revenue
FROM
internal_db.users AS local_users
JOIN
external_service.sales_data AS external_sales
ON local_users.id = external_sales.user_id
WHERE
external_sales.date >= '2023-01-01';
In the example above, the database engine handles the heavy lifting of fetching the relevant rows from the external_service and merging them with the local_db records. The application developer doesn't need to write custom code to handle the API communication.
Comparison: Import vs. Connect
To help you decide, consider the following factors and how they differ between the two approaches:
| Factor | Import (ETL) | Connect (Live) |
|---|---|---|
| Performance | High (local data access) | Variable (depends on source) |
| Data Freshness | Stale (based on sync interval) | Real-time |
| Maintenance | High (pipeline engineering) | Low (connection management) |
| Cost | Storage + Compute for sync | Source system compute usage |
| Complexity | High (ETL/ELT logic) | Low (Config/Virtualization) |
| Security | Copying data (high risk) | Access controls stay at source |
Note: Performance in a connection-based model is highly dependent on the "push-down" capabilities of your query engine. If your engine cannot push the filters and aggregations to the source system, it will be forced to download the entire dataset before processing, which will cause massive performance degradation.
Step-by-Step: Architecting Your Choice
When you are faced with a requirement to integrate external data, follow this structured process to make an informed decision.
Step 1: Evaluate the Volatility of the Source
Ask yourself: "How fast does this data change?" If the data changes every second (e.g., sensor data, stock market ticks), importing is likely a bad idea because the volume of updates would saturate your network and pipeline. If the data is static or changes only once a day (e.g., employee directories, reference tables), importing is a great choice because it provides consistent, fast access.
Step 2: Assess the Query Patterns
If your application needs to perform complex aggregations (e.g., GROUP BY, JOIN, HAVING) on the external data, importing is almost always better. External APIs are rarely optimized for analytical SQL queries. They are usually designed for simple "get by ID" or "list all" operations. Trying to aggregate 100,000 rows through an API will result in timeouts and potential rate-limiting.
Step 3: Check the "Push-Down" Capability
If you lean toward the Connect strategy, test the source system’s ability to handle predicates. Can the source system filter the data before sending it to you? If you are querying a database, ensure your connector can pass the WHERE clause down to the database engine. If the connection tool downloads all data before filtering, you have effectively created a very slow, inefficient version of an import.
Step 4: Define the Security and Compliance Boundaries
Do you need to mask certain fields or apply row-level security? If your internal application has complex security requirements that the source system cannot provide, you must import the data so that you can apply your own security logic in your own database. If the source system already has robust, fine-grained access control, connecting to it allows you to inherit those policies without re-implementing them.
Common Pitfalls and How to Avoid Them
Pitfall 1: The "Everything-to-the-Warehouse" Syndrome
Many architects try to import every piece of external data into a central data warehouse, thinking it will simplify things. This leads to "data swamps" where data is duplicated, misinterpreted, and eventually ignored. Only import data that is truly required for your application’s core functionality.
Pitfall 2: Neglecting API Rate Limits
When connecting to data, it is easy to write a query that inadvertently triggers thousands of API calls. For example, a SELECT * FROM external_users followed by a loop in your application code that calls GET /user/{id}/orders will result in an "N+1" query problem. This will quickly exhaust your API quota.
- Avoidance: Always check if the API supports bulk requests or batch endpoints before deciding to connect directly.
Pitfall 3: Ignoring Schema Evolution
When you import data, the source system might change its schema without warning (e.g., renaming a column, changing a data type). If you don't have robust schema validation in your pipeline, your import will fail, and your application will break.
- Avoidance: Implement a schema registry or a validation step in your ETL process that alerts you to changes before they cause a failure.
Tip: Use a Hybrid Approach You don't have to choose one or the other for the entire project. Many successful architectures use a hybrid approach: they connect to live transactional data for real-time lookups (e.g., user profiles) while importing historical data into a data warehouse for analytical reporting. This gives you the best of both worlds.
Deep Dive: Managing Performance in Connected Systems
If you choose the connection path, you must become an expert in "Query Folding" or "Predicate Push-down." This is the concept where your integration layer intelligently translates your high-level queries into native, optimized queries for the source system.
Consider this scenario: You have an application that needs to display the total sales for a specific region from an external ERP system.
The Inefficient Way (Client-Side Processing):
# Pseudo-code for an inefficient fetch
all_sales = api.get("/sales") # Fetches 1,000,000 records
filtered_sales = [s for s in all_sales if s.region == 'North'] # Filters in Python
total = sum([s.amount for s in filtered_sales]) # Aggregates in Python
This approach is a disaster. It consumes massive bandwidth, high memory, and takes a long time.
The Efficient Way (Predicate Push-down):
# Pseudo-code for an efficient fetch
# The library translates this into: GET /sales?region=North
sales_data = api.get("/sales", params={"region": "North"})
total = sum([s.amount for s in sales_data])
By pushing the filter (region=North) to the API, you reduce the data transfer from 1,000,000 records to perhaps 50,000. Always ensure your integration layer supports these parameters.
Choosing the Right Technology Stack
When you decide to import, you are essentially building a data pipeline. You have several architectural options:
- Batch Processing (The Traditional Way): Tools like Apache Airflow or simple cron jobs that trigger scripts to pull data at set intervals. This is simple and reliable.
- Change Data Capture (CDC): Instead of pulling everything, you stream changes from the source database logs. This is the gold standard for low-latency synchronization.
- Event-Driven Ingestion: Using tools like Kafka to capture events as they happen in the source system. This is the most complex but offers the highest level of responsiveness.
When you decide to connect, you are looking at data virtualization or federated query engines:
- Direct API Integration: Writing custom wrappers to query external services. This is flexible but requires significant maintenance.
- Virtualized Layers (e.g., Trino, Presto): These engines allow you to treat disparate sources as if they were a single database. They are powerful but require expertise to tune for performance.
- GraphQL Federation: Using Apollo or similar to stitch together multiple microservice APIs into a single data graph. This is excellent for modern web applications.
Security Considerations
Security is often the deciding factor in the Import vs. Connect debate. When importing, you must ensure that your data-at-rest is encrypted and that your access control lists (ACLs) are strictly managed. You have now become the "custodian" of that data, meaning you are responsible for its lifecycle, including deletion requests (e.g., GDPR "right to be forgotten").
When connecting, security is simplified because the data never leaves the source. However, you must manage the "credentials" used to connect. Never hardcode API keys or database credentials in your application code. Use a secure vault service (such as HashiCorp Vault, AWS Secrets Manager, or Azure Key Vault) to inject these credentials at runtime.
Callout: The "Compliance" Checklist Before choosing an import strategy, ask these three questions:
- Does the data contain PII (Personally Identifiable Information)?
- Are there specific regional storage requirements (e.g., data must stay in the EU)?
- Do we have the infrastructure to perform regular security audits on our internal copy of the data? If the answer to any of these is "Yes" or "Complicated," strongly consider the Connection approach.
Best Practices for Long-Term Maintenance
Regardless of which path you choose, your architecture must be maintainable. If you choose the import route, treat your ETL code like a first-class product. It needs version control, automated testing, and monitoring. A failing ETL job is just as critical as a failing production feature.
For the connection route, the biggest risk is "Source Drift." If the external team changes their API, your application will break. To mitigate this, implement a contract testing strategy. Use tools that allow you to verify that the external API still conforms to the expected schema before your application tries to consume it.
Checklist for Success:
- Documentation: Maintain a data dictionary that clearly defines where data comes from and how it is updated.
- Monitoring: Use health checks to monitor the latency of your external connections. If an API starts responding slowly, your application should be able to degrade gracefully.
- Caching: Even if you use a "Connect" strategy, consider implementing a short-lived cache (e.g., Redis) for frequently accessed, slow-moving data. This reduces API load and improves user experience.
- Circuit Breakers: If you are connecting to an external service, use a circuit breaker pattern. If the service is down, the breaker trips, preventing your application from hanging while waiting for timeouts.
FAQ: Common Questions
Q: Can I use both Import and Connect in the same application? A: Absolutely. It is common to import static reference data (like country codes or product categories) while connecting live to transactional data (like current order status).
Q: Which is cheaper? A: "Connect" is usually cheaper in terms of direct infrastructure costs, but "Import" can be cheaper in terms of operational costs if you have to pay for API usage or if the external system has a per-query cost.
Q: How do I handle data discrepancies between the two systems? A: This is the hardest part of data architecture. If you import data, you must have a reconciliation process that periodically compares a sample of your imported data with the source to ensure they match. If they don't, you need a way to trigger a re-sync.
Conclusion: Key Takeaways
Designing the data model is not just about choosing a database; it is about choosing how your system interacts with the world. By understanding the trade-offs between importing and connecting, you can build systems that are resilient, performant, and maintainable.
- Importing is for performance and reliability: Choose this when you need complex queries, high availability, or a buffer against source system downtime.
- Connecting is for security and real-time access: Choose this when you need to respect strict data governance, maintain real-time freshness, or avoid the overhead of data duplication.
- The "Push-down" requirement: Always verify if your connection layer can push filters and aggregations to the source system. Never pull entire datasets just to filter them locally.
- Manage the lifecycle: Importing data is a long-term commitment. You are now the owner of that data, including its security, cleanup, and compliance requirements.
- Hybrid is often the answer: Do not feel pressured to pick one method for everything. Use the right tool for each data entity in your system.
- Monitor the health of your bridges: Whether it is an ETL job or a REST API connection, treat your integration points as critical infrastructure. Monitor them, test them, and have a plan for when they fail.
- Start simple: If you are unsure, start with a connection-based approach. It is easier to move to an import-based approach later than it is to untangle a messy, unmanaged data synchronization pipeline.
By applying these principles, you will move beyond simple data retrieval and start architecting sophisticated, enterprise-grade solutions that stand the test of time. Remember that the best architecture is the one that minimizes the amount of "moving parts" while still meeting the performance and security needs of your users.
Enjoying the courses?
Everything stays free. Pro shows fewer ads, doubles your daily points limit so you progress twice as fast, and lets you read each lesson on one page.
- ✓ Fewer advertisements
- ✓ 2× daily points limit
- ✓ Distraction-free lessons