Skip to content
cccskills
FreePublished on GitHub

spark-best-practices

Apache Spark 4.0.2 best practices for PySpark and Scala distributed data processing

The English summary is being prepared. Showing the original description.

See how to install

Files included (1)

  • SKILL.md1.8 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

Apache Spark Best Practices

Version: Spark 4.0.2. Key changes from Spark 3.x: ANSI mode is now default (stricter SQL type coercion and overflow checks), and Spark Connect provides a decoupled client-server protocol for remote Spark access.

Performance Optimization

Broadcast Joins (CRITICAL)

  • Use broadcast(small_df) for small-large table joins
  • Default broadcast threshold: 10MB (spark.sql.autoBroadcastJoinThreshold)
  • Avoid broadcast for tables > 100MB

Shuffles (CRITICAL)

  • Minimize shuffles: expensive operations
  • Use coalesce() to reduce partitions without shuffle
  • Use repartition() only when necessary (causes shuffle)
  • Predicate pushdown: filter before joins

Caching

  • Cache DataFrames used multiple times: df.cache() or df.persist()
  • Choose storage level: MEMORY_ONLY, MEMORY_AND_DISK, DISK_ONLY
  • Unpersist when done: df.unpersist()

Resource Management

Executor Configuration

  • Executor memory: 80% of available memory per executor
  • Executor cores: 4-5 cores per executor (optimal)
  • Dynamic allocation: enable for varying workloads

Partitioning

  • Optimal partition size: 100-200MB
  • Too few partitions: underutilized cluster
  • Too many partitions: task overhead

Data Processing

UDFs

  • Prefer built-in functions over UDFs
  • Use Pandas UDF for vectorized operations
  • Avoid Python UDFs (serialization overhead)

Storage Formats

  • Parquet: default for analytics (columnar, compression)
  • ORC: alternative to Parquet
  • Delta/Iceberg: ACID transactions, time travel

References

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

Pre-action boundary checking — validates agent tool calls against declared capabilities and task contracts

The English summary is being prepared. Showing the original description.

baekenough/second-brain15Updated Oct 8, 2026

Auto-detect project context and optimize harness — deactivate unused agents/skills, suggest missing experts, generate project profile

The English summary is being prepared. Showing the original description.

baekenough/second-brain15Updated Oct 8, 2026

Adversarial code review using attacker mindset — trust boundary, attack surface, business logic, and defense evaluation

The English summary is being prepared. Showing the original description.

baekenough/second-brain15Updated Oct 8, 2026

Apache Airflow best practices for DAG authoring, testing, and production deployment

The English summary is being prepared. Showing the original description.

baekenough/second-brain15Updated Oct 8, 2026

Alembic migration patterns for naming conventions, safety checks, expand-contract, env.py configuration, and CI integration

The English summary is being prepared. Showing the original description.

baekenough/second-brain15Updated Oct 8, 2026

Pre-routing ambiguity analysis — scores request clarity and asks clarifying questions when needed (inspired by ouroboros)

The English summary is being prepared. Showing the original description.

baekenough/second-brain15Updated Oct 8, 2026

See all skills by baekenough

Report a problem with this skill